<commit_before>/*
 *   Copyright 2002-2004 <NAME> <<EMAIL>>
 *
 *   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 2
 *   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, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <stddef.h>
#include <math.h>

#include <X11/Xdefs.h>
#include "synaptics.h"

static void show_hw_info(SynapticsSHM* synshm)
{
    printf("Hardware properties:\n");
    if (synshm->isSynaptics) {
	printf("    Model Id     = %08lx\n", synshm->model_id);
	printf("    Capabilities = %08lx\n", synshm->capabilities);
	printf("    Identity     = %08lx\n", synshm->identity);
    } else {
	printf("    No touchpad found\n");
	printf("    Do you use a newer kernel than 2.4?\n");
	printf("    Then browse the messages or boot.msg for the hardware info\n");
    }
}

/* ---------------------------------------------------------------------- */

enum ParaType {
    PT_INT,
    PT_BOOL,
    PT_DOUBLE
};

struct Parameter {
    char* name;				    /* Name of parameter */
    int offset;				    /* Offset in shared memory area */
    enum ParaType type;			    /* Type of parameter */
    double min_val;			    /* Minimum allowed value */
    double max_val;			    /* Maximum allowed value */
};

#define DEFINE_PAR(name, memb, type, min_val, max_val) \
{ name, offsetof(SynapticsSHM, memb), (type), (min_val), (max_val) }

static struct Parameter params[] = {
    DEFINE_PAR("LeftEdge",             left_edge,               PT_INT,    0, 10000),
    DEFINE_PAR("RightEdge",            right_edge,              PT_INT,    0, 10000),
    DEFINE_PAR("TopEdge",              top_edge,                PT_INT,    0, 10000),
    DEFINE_PAR("BottomEdge",           bottom_edge,             PT_INT,    0, 10000),
    DEFINE_PAR("FingerLow",            finger_low,              PT_INT,    0, 255),
    DEFINE_PAR("FingerHigh",           finger_high,             PT_INT,    0, 255),
    DEFINE_PAR("MaxTapTime",           tap_time,                PT_INT,    0, 1000),
    DEFINE_PAR("MaxTapMove",           tap_move,                PT_INT,    0, 2000),
    DEFINE_PAR("EmulateMidButtonTime", emulate_mid_button_time, PT_INT,    0, 1000),
    DEFINE_PAR("VertScrollDelta",      scroll_dist_vert,        PT_INT,    5, 1000),
    DEFINE_PAR("HorizScrollDelta",     scroll_dist_horiz,       PT_INT,    5, 1000),
    DEFINE_PAR("MinSpeed",             min_speed,               PT_DOUBLE, 0, 1.0),
    DEFINE_PAR("MaxSpeed",             max_speed,               PT_DOUBLE, 0, 1.0),
    DEFINE_PAR("AccelFactor",          accl,                    PT_DOUBLE, 0, 0.2),
    DEFINE_PAR("EdgeMotionSpeed",      edge_motion_speed,       PT_INT,    0, 400),
    DEFINE_PAR("UpDownScrolling",      updown_button_scrolling, PT_BOOL,   0, 1),
    DEFINE_PAR("TouchpadOff",          touchpad_off,            PT_BOOL,   0, 1),
    DEFINE_PAR("LockedDrags",          locked_drags,            PT_BOOL,   0, 1),
    DEFINE_PAR("RTCornerButton",       tap_action[RT_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("RBCornerButton",       tap_action[RB_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("LTCornerButton",       tap_action[LT_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("LBCornerButton",       tap_action[LB_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("TapButton1",           tap_action[F1_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("TapButton2",           tap_action[F2_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("TapButton3",           tap_action[F3_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("CircularScrolling",    circular_scrolling,      PT_BOOL,   0, 1),
    DEFINE_PAR("CircScrollDelta",      scroll_dist_circ,        PT_DOUBLE, .01, 3),
    DEFINE_PAR("CircScrollTrigger",    circular_trigger,        PT_INT,    0, 8),
    { 0, 0, 0, 0, 0 }
};

static void show_settings(SynapticsSHM* synshm)
{
    int i;

    printf("Parameter settings:\n");
    for (i = 0; params[i].name; i++) {
	struct Parameter* par = &params[i];
	switch (par->type) {
	case PT_INT:
	    printf("    %-20s = %d\n", par->name, *(int*)((char*)synshm + par->offset));
	    break;
	case PT_BOOL:
	    printf("    %-20s = %d\n", par->name, *(Bool*)((char*)synshm + par->offset));
	    break;
	case PT_DOUBLE:
	    printf("    %-20s = %g\n", par->name, *(double*)((char*)synshm + par->offset));
	    break;
	}
    }
}

static void set_variables(SynapticsSHM* synshm, int argc, char* argv[], int first_cmd)
{
    int i;
    for (i = first_cmd; i < argc; i++) {
	char* cmd = argv[i];
	char* eqp = index(cmd, '=');
	if (eqp) {
	    int j;
	    int found = 0;
	    *eqp = 0;
	    for (j = 0; params[j].name; j++) {
		if (strcasecmp(cmd, params[j].name) == 0) {
		    found = 1;
		    break;
		}
	    }
	    if (found) {
		double val = atof(&eqp[1]);
		struct Parameter* par = &params[j];

		if (val < par->min_val)
		    val = par->min_val;
		if (val > par->max_val)
		    val = par->max_val;

		switch (par->type) {
		case PT_INT:
		    *(int*)((char*)synshm + par->offset) = (int)rint(val);
		    break;
		case PT_BOOL:
		    *(Bool*)((char*)synshm + par->offset) = (Bool)rint(val);
		    break;
		case PT_DOUBLE:
		    *(double*)((char*)synshm + par->offset) = val;
		    break;
		}
	    } else {
		printf("Unknown parameter %s\n", cmd);
	    }
	} else {
	    printf("Invalid command: %s\n", cmd);
	}
    }
}

static int is_equal(SynapticsSHM* s1, SynapticsSHM* s2)
{
    return ((s1->x           == s2->x) &&
	    (s1->y           == s2->y) &&
	    (s1->z           == s2->z) &&
	    (s1->numFingers  == s2->numFingers) &&
	    (s1->fingerWidth == s2->fingerWidth) &&
	    (s1->left        == s2->left) &&
	    (s1->right       == s2->right) &&
	    (s1->up          == s2->up) &&
	    (s1->down        == s2->down) &&
	    (s1->middle      == s2->middle) &&
	    (s1->guest_left  == s2->guest_left) &&
	    (s1->guest_mid   == s2->guest_mid) &&
	    (s1->guest_right == s2->guest_right) &&
	    (s1->guest_dx    == s2->guest_dx) &&
	    (s1->guest_dy    == s2->guest_dy));
}

static double get_time()<commit_msg>The is_equal() function in synclient.c forgot to check multibuttons.<commit_after>/*
 *   Copyright 2002-2004 <NAME> <<EMAIL>>
 *
 *   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 2
 *   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, write to the Free Software
 *   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 *
 */

#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/ipc.h>
#include <sys/shm.h>
#include <sys/time.h>
#include <unistd.h>
#include <string.h>
#include <stddef.h>
#include <math.h>

#include <X11/Xdefs.h>
#include "synaptics.h"

static void show_hw_info(SynapticsSHM* synshm)
{
    printf("Hardware properties:\n");
    if (synshm->isSynaptics) {
	printf("    Model Id     = %08lx\n", synshm->model_id);
	printf("    Capabilities = %08lx\n", synshm->capabilities);
	printf("    Identity     = %08lx\n", synshm->identity);
    } else {
	printf("    No touchpad found\n");
	printf("    Do you use a newer kernel than 2.4?\n");
	printf("    Then browse the messages or boot.msg for the hardware info\n");
    }
}

/* ---------------------------------------------------------------------- */

enum ParaType {
    PT_INT,
    PT_BOOL,
    PT_DOUBLE
};

struct Parameter {
    char* name;				    /* Name of parameter */
    int offset;				    /* Offset in shared memory area */
    enum ParaType type;			    /* Type of parameter */
    double min_val;			    /* Minimum allowed value */
    double max_val;			    /* Maximum allowed value */
};

#define DEFINE_PAR(name, memb, type, min_val, max_val) \
{ name, offsetof(SynapticsSHM, memb), (type), (min_val), (max_val) }

static struct Parameter params[] = {
    DEFINE_PAR("LeftEdge",             left_edge,               PT_INT,    0, 10000),
    DEFINE_PAR("RightEdge",            right_edge,              PT_INT,    0, 10000),
    DEFINE_PAR("TopEdge",              top_edge,                PT_INT,    0, 10000),
    DEFINE_PAR("BottomEdge",           bottom_edge,             PT_INT,    0, 10000),
    DEFINE_PAR("FingerLow",            finger_low,              PT_INT,    0, 255),
    DEFINE_PAR("FingerHigh",           finger_high,             PT_INT,    0, 255),
    DEFINE_PAR("MaxTapTime",           tap_time,                PT_INT,    0, 1000),
    DEFINE_PAR("MaxTapMove",           tap_move,                PT_INT,    0, 2000),
    DEFINE_PAR("EmulateMidButtonTime", emulate_mid_button_time, PT_INT,    0, 1000),
    DEFINE_PAR("VertScrollDelta",      scroll_dist_vert,        PT_INT,    5, 1000),
    DEFINE_PAR("HorizScrollDelta",     scroll_dist_horiz,       PT_INT,    5, 1000),
    DEFINE_PAR("MinSpeed",             min_speed,               PT_DOUBLE, 0, 1.0),
    DEFINE_PAR("MaxSpeed",             max_speed,               PT_DOUBLE, 0, 1.0),
    DEFINE_PAR("AccelFactor",          accl,                    PT_DOUBLE, 0, 0.2),
    DEFINE_PAR("EdgeMotionSpeed",      edge_motion_speed,       PT_INT,    0, 400),
    DEFINE_PAR("UpDownScrolling",      updown_button_scrolling, PT_BOOL,   0, 1),
    DEFINE_PAR("TouchpadOff",          touchpad_off,            PT_BOOL,   0, 1),
    DEFINE_PAR("LockedDrags",          locked_drags,            PT_BOOL,   0, 1),
    DEFINE_PAR("RTCornerButton",       tap_action[RT_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("RBCornerButton",       tap_action[RB_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("LTCornerButton",       tap_action[LT_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("LBCornerButton",       tap_action[LB_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("TapButton1",           tap_action[F1_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("TapButton2",           tap_action[F2_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("TapButton3",           tap_action[F3_TAP],      PT_INT,    0, 3),
    DEFINE_PAR("CircularScrolling",    circular_scrolling,      PT_BOOL,   0, 1),
    DEFINE_PAR("CircScrollDelta",      scroll_dist_circ,        PT_DOUBLE, .01, 3),
    DEFINE_PAR("CircScrollTrigger",    circular_trigger,        PT_INT,    0, 8),
    { 0, 0, 0, 0, 0 }
};

static void show_settings(SynapticsSHM* synshm)
{
    int i;

    printf("Parameter settings:\n");
    for (i = 0; params[i].name; i++) {
	struct Parameter* par = &params[i];
	switch (par->type) {
	case PT_INT:
	    printf("    %-20s = %d\n", par->name, *(int*)((char*)synshm + par->offset));
	    break;
	case PT_BOOL:
	    printf("    %-20s = %d\n", par->name, *(Bool*)((char*)synshm + par->offset));
	    break;
	case PT_DOUBLE:
	    printf("    %-20s = %g\n", par->name, *(double*)((char*)synshm + par->offset));
	    break;
	}
    }
}

static void set_variables(SynapticsSHM* synshm, int argc, char* argv[], int first_cmd)
{
    int i;
    for (i = first_cmd; i < argc; i++) {
	char* cmd = argv[i];
	char* eqp = index(cmd, '=');
	if (eqp) {
	    int j;
	    int found = 0;
	    *eqp = 0;
	    for (j = 0; params[j].name; j++) {
		if (strcasecmp(cmd, params[j].name) == 0) {
		    found = 1;
		    break;
		}
	    }
	    if (found) {
		double val = atof(&eqp[1]);
		struct Parameter* par = &params[j];

		if (val < par->min_val)
		    val = par->min_val;
		if (val > par->max_val)
		    val = par->max_val;

		switch (par->type) {
		case PT_INT:
		    *(int*)((char*)synshm + par->offset) = (int)rint(val);
		    break;
		case PT_BOOL:
		    *(Bool*)((char*)synshm + par->offset) = (Bool)rint(val);
		    break;
		case PT_DOUBLE:
		    *(double*)((char*)synshm + par->offset) = val;
		    break;
		}
	    } else {
		printf("Unknown parameter %s\n", cmd);
	    }
	} else {
	    printf("Invalid command: %s\n", cmd);
	}
    }
}

static int is_equal(SynapticsSHM* s1, SynapticsSHM* s2)
{
    int i;

    if ((s1->x           != s2->x) ||
	(s1->y           != s2->y) ||
	(s1->z           != s2->z) ||
	(s1->numFingers  != s2->numFingers) ||
	(s1->fingerWidth != s2->fingerWidth) ||
	(s1->left        != s2->left) ||
	(s1->right       != s2->right) ||
	(s1->up          != s2->up) ||
	(s1->down        != s2->down) ||
	(s1->middle      != s2->middle) ||
	(s1->guest_left  != s2->guest_left) ||
	(s1->guest_mid   != s2->guest_mid) ||
	(s1->guest_right != s2->guest_right) ||
	(s1->guest_dx    != s2->guest_dx) ||
	(s1->guest_dy    != s2->guest_dy))
	return 0;

    for (i = 0; i < 8; i++)
	if (s1->multi[i] != s2->multi[i])
	    return 0;

    return 1;
}

static double get_time()
{'fraction_non_alphanumeric': 0.15880398671096346, 'fraction_numerical': 0.02709486895533407, 'mean_word_length': 2.2870662460567823, 'pattern_counts': {'":': 0, '<': 36, '<?xml version=': 0, '>': 133, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3890919', 'n_tokens_mistral': 5234, 'n_tokens_neox': 4798, 'n_words': 1148}