Commit 7b320c7b authored by Michael Natterer's avatar Michael Natterer 😴

Get rid of DOS line endings

parent 223ae53f
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <glib.h>
#ifdef G_OS_WIN32
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <process.h>
#endif
#ifdef G_OS_UNIX
/* For get_backtrace() */
#include <stdlib.h>
#include <string.h>
#include <execinfo.h>
#endif
#include "base-utils.h"
#define NUM_PROCESSORS_DEFAULT 1
#define MAX_FUNC 100
/* public functions */
gint
get_pid (void)
{
return (gint) getpid ();
}
gint
get_number_of_processors (void)
{
gint retval = NUM_PROCESSORS_DEFAULT;
#ifdef G_OS_UNIX
#if defined(HAVE_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
retval = sysconf (_SC_NPROCESSORS_ONLN);
#endif
#endif
#ifdef G_OS_WIN32
SYSTEM_INFO system_info;
GetSystemInfo (&system_info);
retval = system_info.dwNumberOfProcessors;
#endif
return retval;
}
guint64
get_physical_memory_size (void)
{
#ifdef G_OS_UNIX
#if defined(HAVE_UNISTD_H) && defined(_SC_PHYS_PAGES) && defined (_SC_PAGE_SIZE)
return (guint64) sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGE_SIZE);
#endif
#endif
#ifdef G_OS_WIN32
# if defined(_MSC_VER) && (_MSC_VER <= 1200)
MEMORYSTATUS memory_status;
memory_status.dwLength = sizeof (memory_status);
GlobalMemoryStatus (&memory_status);
return memory_status.dwTotalPhys;
# else
/* requires w2k and newer SDK than provided with msvc6 */
MEMORYSTATUSEX memory_status;
memory_status.dwLength = sizeof (memory_status);
if (GlobalMemoryStatusEx (&memory_status))
return memory_status.ullTotalPhys;
# endif
#endif
return 0;
}
/**
* get_backtrace:
*
* Returns: The current stack trace. Free with g_free(). Mainly meant
* for debugging, for example storing the allocation stack traces for
* objects to hunt down leaks.
**/
char *
get_backtrace (void)
{
#ifdef G_OS_UNIX
void *functions[MAX_FUNC];
char **function_names;
int n_functions;
int i;
GString *result;
/* Get symbols */
n_functions = backtrace (functions, MAX_FUNC);
function_names = backtrace_symbols (functions, n_functions);
/* Construct stack trace */
result = g_string_new ("");
for (i = 0; i < n_functions; i++)
g_string_append_printf (result, "%s\n", function_names[i]);
/* We must not free the function names themselves, we only need to
* free the array that points to them
*/
free (function_names);
return g_string_free (result, FALSE/*free_segment*/);
#else
return g_strdup ("backtrace() only available with GNU libc\n");
#endif
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#include <glib.h>
#ifdef G_OS_WIN32
#define _WIN32_WINNT 0x0500
#include <windows.h>
#include <process.h>
#endif
#ifdef G_OS_UNIX
/* For get_backtrace() */
#include <stdlib.h>
#include <string.h>
#include <execinfo.h>
#endif
#include "base-utils.h"
#define NUM_PROCESSORS_DEFAULT 1
#define MAX_FUNC 100
/* public functions */
gint
get_pid (void)
{
return (gint) getpid ();
}
gint
get_number_of_processors (void)
{
gint retval = NUM_PROCESSORS_DEFAULT;
#ifdef G_OS_UNIX
#if defined(HAVE_UNISTD_H) && defined(_SC_NPROCESSORS_ONLN)
retval = sysconf (_SC_NPROCESSORS_ONLN);
#endif
#endif
#ifdef G_OS_WIN32
SYSTEM_INFO system_info;
GetSystemInfo (&system_info);
retval = system_info.dwNumberOfProcessors;
#endif
return retval;
}
guint64
get_physical_memory_size (void)
{
#ifdef G_OS_UNIX
#if defined(HAVE_UNISTD_H) && defined(_SC_PHYS_PAGES) && defined (_SC_PAGE_SIZE)
return (guint64) sysconf (_SC_PHYS_PAGES) * sysconf (_SC_PAGE_SIZE);
#endif
#endif
#ifdef G_OS_WIN32
# if defined(_MSC_VER) && (_MSC_VER <= 1200)
MEMORYSTATUS memory_status;
memory_status.dwLength = sizeof (memory_status);
GlobalMemoryStatus (&memory_status);
return memory_status.dwTotalPhys;
# else
/* requires w2k and newer SDK than provided with msvc6 */
MEMORYSTATUSEX memory_status;
memory_status.dwLength = sizeof (memory_status);
if (GlobalMemoryStatusEx (&memory_status))
return memory_status.ullTotalPhys;
# endif
#endif
return 0;
}
/**
* get_backtrace:
*
* Returns: The current stack trace. Free with g_free(). Mainly meant
* for debugging, for example storing the allocation stack traces for
* objects to hunt down leaks.
**/
char *
get_backtrace (void)
{
#ifdef G_OS_UNIX
void *functions[MAX_FUNC];
char **function_names;
int n_functions;
int i;
GString *result;
/* Get symbols */
n_functions = backtrace (functions, MAX_FUNC);
function_names = backtrace_symbols (functions, n_functions);
/* Construct stack trace */
result = g_string_new ("");
for (i = 0; i < n_functions; i++)
g_string_append_printf (result, "%s\n", function_names[i]);
/* We must not free the function names themselves, we only need to
* free the array that points to them
*/
free (function_names);
return g_string_free (result, FALSE/*free_segment*/);
#else
return g_strdup ("backtrace() only available with GNU libc\n");
#endif
}
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BASE_H__
#define __BASE_H__
gint get_pid (void);
gint get_number_of_processors (void);
guint64 get_physical_memory_size (void);
char * get_backtrace (void);
#endif /* __BASE_H__ */
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995 Spencer Kimball and Peter Mattis
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef __BASE_H__
#define __BASE_H__
gint get_pid (void);
gint get_number_of_processors (void);
guint64 get_physical_memory_size (void);
char * get_backtrace (void);
#endif /* __BASE_H__ */
/Makefile
/Makefile
/Makefile.in
\ No newline at end of file
SUBDIRS = \
SUBDIRS = \
windows
\ No newline at end of file
# Version resources for Microsoft Windows
SUFFIXES = .rc .rc.o
.rc.rc.o: $(top_srcdir)/build/windows/gimp.rc
$(WINDRES) --define ORIGINALFILENAME_STR="$*$(EXEEXT)" \
--define INTERNALNAME_STR="$*" \
--define TOP_SRCDIR="$(top_srcdir)" \
-I$(top_srcdir)/app \
$< $@
# Version resources for Microsoft Windows
SUFFIXES = .rc .rc.o
.rc.rc.o: $(top_srcdir)/build/windows/gimp.rc
$(WINDRES) --define ORIGINALFILENAME_STR="$*$(EXEEXT)" \
--define INTERNALNAME_STR="$*" \
--define TOP_SRCDIR="$(top_srcdir)" \
-I$(top_srcdir)/app \
$< $@
/* GIMP - The GNU Image Manipulation Program
* Copyright (C) 1995-1997 Spencer Kimball and Peter Mattis
*
* controller_dx_dinput.c
* Copyright (C) 2004-2007 Sven Neumann <sven@gimp.org>
* Michael Natterer <mitch@gimp.org>
* Tor Lillqvist <tml@iki.fi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* When using gcc with the February 2007 version of the DirectX SDK,
* at least, you need to fix a couple of duplicate typedefs in the
* DirectX <dinput.h>. Unfortunately I can't include the diff here,
* both for copyright reasons, and because that would confuse the C
* lexer even if inside #if 0.
*/
#include "config.h"
#include <errno.h>
#include <string.h>
#include <math.h>
#define _WIN32_WINNT 0x0501
#include <windows.h>
#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include <gtk/gtk.h>
#include "libgimpconfig/gimpconfig.h"
#include "libgimpmodule/gimpmodule.h"
#include "libgimpwidgets/gimpwidgets.h"
#define GIMP_ENABLE_CONTROLLER_UNDER_CONSTRUCTION
#include "libgimpwidgets/gimpcontroller.h"
#include "gimpinputdevicestore.h"
#include "libgimp/libgimp-intl.h"
enum
{
PROP_0,
PROP_DEVICE,
PROP_DEVICE_STORE
};
#define NUM_EVENTS_PER_BUTTON 3 /* Button click, press and release */
#define NUM_EVENTS_PER_AXIS 2 /* Axis decrease and increase */
#define NUM_EVENTS_PER_SLIDER 2 /* Slider decrease and increase */
#define NUM_EVENTS_PER_POV 3 /* POV view vector X and Y view and return */
#define CONTROLLER_TYPE_DX_DINPUT (controller_dx_dinput_get_type ())
#define CONTROLLER_DX_DINPUT(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), CONTROLLER_TYPE_DX_DINPUT, ControllerDXDInput))
#define CONTROLLER_DX_DINPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), CONTROLLER_TYPE_DX_DINPUT, ControllerDXDInputClass))
#define CONTROLLER_IS_DX_DINPUT(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), CONTROLLER_TYPE_DX_DINPUT))
#define CONTROLLER_IS_DX_DINPUT_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), CONTROLLER_TYPE_DX_DINPUT))
typedef struct _DXDInputSource DXDInputSource;
typedef struct _ControllerDXDInput ControllerDXDInput;
typedef struct _ControllerDXDInputClass ControllerDXDInputClass;
struct _DXDInputSource
{
GSource source;
ControllerDXDInput *controller;
};
struct _ControllerDXDInput
{
GimpController parent_instance;
GimpInputDeviceStore *store;
LPDIRECTINPUTDEVICE8W didevice8;
HANDLE event;
GPollFD *pollfd;
gint num_buttons;
gint num_button_events;
gint num_axes;
gint num_axis_events;
gint num_sliders;
gint num_slider_events;
gint num_povs;
gint num_pov_events;
gint num_events;
gchar **event_names;
gchar **event_blurbs;
DIDATAFORMAT *format;
guchar *prevdata;
gchar *guid;
GSource *source;
/* Variables used by enumeration callbacks only*/
gint bei, bi, aei, ai, sei, si, pei, pi;
};
struct _ControllerDXDInputClass
{
GimpControllerClass parent_class;
};
GType controller_dx_dinput_get_type (void);
static void dx_dinput_dispose (GObject *object);
static void dx_dinput_finalize (GObject *object);
static void dx_dinput_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec);
static void dx_dinput_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec);
static gint dx_dinput_get_n_events (GimpController *controller);
static const gchar * dx_dinput_get_event_name (GimpController *controller,
gint event_id);
static const gchar * dx_dinput_get_event_blurb (GimpController *controller,
gint event_id);
static void dx_dinput_device_changed (ControllerDXDInput *controller,
const gchar *guid);
static gboolean dx_dinput_set_device (ControllerDXDInput *controller,
const gchar *guid);
static const GimpModuleInfo dx_dinput_info =
{
GIMP_MODULE_ABI_VERSION,
N_("DirectX DirectInput event controller"),
"Tor Lillqvist <tml@iki.fi>",
"v0.1",
"(c) 2004-2007, released under the GPL",
"2004-2007"
};
G_DEFINE_DYNAMIC_TYPE (ControllerDXDInput, controller_dx_dinput,
GIMP_TYPE_CONTROLLER)
G_MODULE_EXPORT const GimpModuleInfo *
gimp_module_query (GTypeModule *module)
{
return &dx_dinput_info;
}
G_MODULE_EXPORT gboolean
gimp_module_register (GTypeModule *module)
{
gimp_input_device_store_register_types (module);
controller_dx_dinput_register_type (module);
return TRUE;
}
static void
controller_dx_dinput_class_init (ControllerDXDInputClass *klass)
{
GimpControllerClass *controller_class = GIMP_CONTROLLER_CLASS (klass);
GObjectClass *object_class = G_OBJECT_CLASS (klass);
object_class->dispose = dx_dinput_dispose;
object_class->finalize = dx_dinput_finalize;
object_class->get_property = dx_dinput_get_property;
object_class->set_property = dx_dinput_set_property;
g_object_class_install_property (object_class, PROP_DEVICE,
g_param_spec_string ("device",
_("Device:"),
_("The device to read DirectInput events from."),
NULL,
GIMP_CONFIG_PARAM_FLAGS));
g_object_class_install_property (object_class, PROP_DEVICE_STORE,
g_param_spec_object ("device-values",
NULL, NULL,
GIMP_TYPE_INPUT_DEVICE_STORE,
G_PARAM_READABLE));
controller_class->name = _("DirectX DirectInput");
controller_class->help_id = "gimp-controller-directx-directinput";
controller_class->stock_id = GIMP_STOCK_CONTROLLER_LINUX_INPUT;
controller_class->get_n_events = dx_dinput_get_n_events;
controller_class->get_event_name = dx_dinput_get_event_name;
controller_class->get_event_blurb = dx_dinput_get_event_blurb;
}
static void
controller_dx_dinput_class_finalize (ControllerDXDInputClass *klass)
{
}
static void
controller_dx_dinput_init (ControllerDXDInput *controller)
{
controller->store = gimp_input_device_store_new ();
if (controller->store)
{
g_signal_connect_swapped (controller->store, "device-added",
G_CALLBACK (dx_dinput_device_changed),
controller);
g_signal_connect_swapped (controller->store, "device-removed",
G_CALLBACK (dx_dinput_device_changed),
controller);
}
}
static void
dx_dinput_dispose (GObject *object)
{
ControllerDXDInput *controller = CONTROLLER_DX_DINPUT (object);
dx_dinput_set_device (controller, NULL);
G_OBJECT_CLASS (controller_dx_dinput_parent_class)->dispose (object);
}
static void
dx_dinput_finalize (GObject *object)
{
ControllerDXDInput *controller = CONTROLLER_DX_DINPUT (object);
if (controller->source != NULL)
{
g_source_remove_poll (controller->source, controller->pollfd);
g_source_remove (g_source_get_id (controller->source));
g_source_unref (controller->source);
}
if (controller->didevice8)
IDirectInputDevice8_SetEventNotification (controller->didevice8, NULL);
if (controller->format != NULL)
{
g_free (controller->format->rgodf);
g_free (controller->format);
controller->format = NULL;
}
g_free (controller->prevdata);
controller->prevdata = NULL;
if (controller->event != NULL)
{
CloseHandle (controller->event);
controller->event = 0;
}
if (controller->store)
{
g_object_unref (controller->store);
controller->store = NULL;
}
G_OBJECT_CLASS (controller_dx_dinput_parent_class)->finalize (object);
}
static void
dx_dinput_set_property (GObject *object,
guint property_id,
const GValue *value,
GParamSpec *pspec)
{
ControllerDXDInput *controller = CONTROLLER_DX_DINPUT (object);
switch (property_id)
{
case PROP_DEVICE:
dx_dinput_set_device (controller, g_value_get_string (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static void
dx_dinput_get_property (GObject *object,
guint property_id,
GValue *value,
GParamSpec *pspec)
{
ControllerDXDInput *controller = CONTROLLER_DX_DINPUT (object);
switch (property_id)
{
case PROP_DEVICE:
g_value_set_string (value, controller->guid);
break;
case PROP_DEVICE_STORE:
g_value_set_object (value, controller->store);
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
break;
}
}
static gint
dx_dinput_get_n_events (GimpController *controller)
{
ControllerDXDInput *cdxdi = (ControllerDXDInput *) controller;
return cdxdi->num_events;
}
static const gchar *
dx_dinput_get_event_name
(GimpController *controller,
gint event_id)
{
ControllerDXDInput *cdxdi = (ControllerDXDInput *) controller;
if (event_id < 0 || event_id >= cdxdi->num_events)
return NULL;
return cdxdi->event_names[event_id];
}
static const gchar *
dx_dinput_get_event_blurb (GimpController *controller,
gint event_id)
{
ControllerDXDInput *cdxdi = (ControllerDXDInput *) controller;
if (event_id < 0 || event_id >= cdxdi->num_events)
return NULL;
return cdxdi->event_blurbs[event_id];
}
static BOOL CALLBACK
count_objects (const DIDEVICEOBJECTINSTANCEW *doi,
void *user_data)
{
ControllerDXDInput *controller = (ControllerDXDInput *) user_data;
HRESULT hresult;
DIPROPRANGE range;
if (doi->dwType & DIDFT_AXIS)
{
/* Set reported range to physical range, not to give upper
* level software any false impression of higher accuracy.
*/
range.diph.dwSize = sizeof (DIPROPRANGE);
range.diph.dwHeaderSize = sizeof (DIPROPHEADER);
range.diph.dwObj = doi->dwType;
range.diph.dwHow = DIPH_BYID;