rendered paste body
#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <getopt.h>
#include <math.h>
#include <string.h>
#define DEF_XY_EXP 1.6
#define DEF_Z_EXP 1.2
#define DEF_Z_MULT 0.02
#define DEF_INDEV "/dev/mouse"
#define DEF_OUTDEV "/dev/imouse"
void usage();
main(int argc, char *argv[])
{
FILE *in, *out;
unsigned char mousedev_imps_seq[] = { 0xf3, 200, 0xf3, 100, 0xf3, 80 };
char *indev = DEF_INDEV;
char *outdev = DEF_OUTDEV;
int ch;
int c;
while (1) {
static struct option long_options[] =
{
{"input", required_argument, 0, 'i'},
{"output", required_argument, 0, 'o'},
{"vx", required_argument, 0, 'x'},
{"vz", required_argument, 0, 'z'},
{"mz", required_argument, 0, 'm'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
int option_index = 0;
ch = getopt_long (argc, argv, "i:o:x:z:m:h", long_options, &option_index);
/* Detect the end of the options. */
if (ch == -1)
break;
switch (ch) {
case 'i':
indev = strdup(optarg);
break;
case 'o':
outdev = strdup(optarg);
break;
break;
case 'h':
usage();
exit(1);
case '?':
usage();
exit(1);
break;
default:
usage();
exit(1);
}
}
signal(SIGPIPE, SIG_IGN);
while (1) {
out = fopen(outdev, "w");
in = fopen(indev, "w");
fwrite(mousedev_imps_seq,1,sizeof(mousedev_imps_seq), in);
fclose(in);
fclose(out);
if ((in == NULL) || (out == NULL)) {
printf("%s: unable to open files\n", argv[0]);
exit(1);
}
fread(&c,1,sizeof(int),in);
printf("%d\n", c);
}
}
void usage() {
printf("usage:\n");
printf("-h | --help \t output this help message\n");
printf("-i | --input \t input-device (default: %s)\n",DEF_INDEV);
printf("-o | --output \t pseudo-mouse-device (default: %s)\n",DEF_OUTDEV);
printf("Acceleration:\n");
printf("-x | --vx\t XY_ACCEL_EXP (default: %.1f)\n",DEF_XY_EXP);
printf("-z | --vz\t Z_ACCEL_EXP (default: %.1f)\n",DEF_Z_EXP);
printf("-m | --mz\t Z_ACCEL_MULT (default: %.2f)\n",DEF_Z_MULT);
}