示例#1
0
/* Add key to the send queue. If it is a modifier its bit pattern is
   added to the modifier byte. */
void key_press(uint8_t k) {
  uint8_t i;
  key[k].pressed = true;
  if(IS_MODIFIER(layout[k]))
    mod_keys |= layout[k].value;
  else {
    for(i = QUEUE_LENGTH-1; i > 0; i--)
      queue[i] = queue[i-1];
    queue[0] = k;
  }
  send();
}
示例#2
0
/* Remove key from the send queue. If it is a modifier key its bit
   pattern is removed from the modifier byte. */
void key_release(uint8_t k) {
  uint8_t i;
  key[k].pressed = false;
  if(IS_MODIFIER(layout[k]))
    mod_keys &= ~layout[k].value;
  else {
    for(i = 0; i < QUEUE_LENGTH; i++)
      if(queue[i]==k)
        break;
    for(i = i; i < QUEUE_LENGTH; i++)
      queue[i] = queue[i+1];
  }
  send();
}
示例#3
0
void key_release(uint8_t k) {
  key[k].pressed = false;
  if (magic_mode) {
    magic_key_release(k);
  } else {
    if (recording_mode) {
      add_to_replay_buf(k);
    }
    if(IS_MODIFIER(layout[k])) {
      ll_modifier_release(layout[k].value);
    } else {
      ll_key_release(layout[k].value);
    }
  }
}
示例#4
0
void key_press(uint8_t k) {
  key[k].pressed = true;
  if (magic_mode) {
    magic_key_press(k);
  } else if (is_magic_key(k)) {
    // Pressing the magic key activates magic mode, except
    // if we're in recording mode, in which case it exits
    // recording mode.
    if (recording_mode) {
      recording_mode = 0;
    } else {
      magic_mode = 1;
    }
  } else {
    if (recording_mode) {
      add_to_replay_buf(k);
    }
    if(IS_MODIFIER(layout[k])) {
      ll_modifier_press(layout[k].value);
    } else {
      ll_key_press(layout[k].value);
    }
  }
}
示例#5
0
void key_press(uint8_t k) {
  uint8_t i;

  key[k].pressed = 0x80 | active_layer;
  if(current_dualrole_key != 255) {
    if(!dualrole_modifier_possible && IS_NORMAL(k) && WAS_TAPPABLE_LAYERSHIFT(current_dualrole_key) ) {//TODO do we need dualrole_modifier_possible ?
      for(i = 5; i > 0; i--)
        queue[i] = queue[i-1];
      queue[0] = current_dualrole_key;

      active_layer = DISENGAGE_LAYER(current_dualrole_key);

      send();

      for(i = 0; i < 6; i++)
        if(queue[i]==current_dualrole_key)
          break;
      for(i = i; i < 6; i++)
        queue[i] = queue[i+1];
      send();

      current_dualrole_key = 255;
      dualrole_tap_possible = false;
      dualrole_modifier_possible = false;
      dualrole_modifier_impossible_until_tick = 0;
      dualrole_tap_impossible_after_tick = 0;
    }
  }

  if(IS_TAPPABLE_MODIFIER(k)) {
    dualrole_tap_possible = true;
    dualrole_modifier_possible = false;
    dualrole_tap_impossible_after_tick = tick + LONGEST_TAP_DURATION;
    dualrole_modifier_impossible_until_tick = tick + SHORTEST_MODIFIER_DURATION;
    current_dualrole_key = k;

    mod_keys |= GET_TAPPABLE_MODIFIER(k);
    send();
  }
  else if(IS_TAPPABLE_LAYERSHIFT(k)) {
    dualrole_tap_possible = true;
    dualrole_modifier_possible = false;
    dualrole_tap_impossible_after_tick = tick + LONGEST_TAP_DURATION;
    dualrole_modifier_impossible_until_tick = tick + SHORTEST_MODIFIER_DURATION;
    current_dualrole_key = k;

    active_layer = ENGAGE_LAYER(k);
  }
  else if(IS_LAYERLOCK(k)) {
    dualrole_tap_possible = true;
    dualrole_modifier_possible = false;
    current_dualrole_key = k;

    active_layer = ENGAGE_LAYER(k);
  }
  else if(IS_MODIFIER(k)) {
    mod_keys |= KEY(k);

    if(IS_MODDED(k)) {
      mod_keys |= ~GET_ADDITIONAL_MODIFIERS(k);
    }

    dualrole_tap_possible = false;
    send();
  }
  else {
    dualrole_tap_possible = false;
    for(i = 5; i > 0; i--)
      queue[i] = queue[i-1];
    queue[0] = k;
    send();
  }
}
示例#6
0
/* parse command line arguments and preform needed actions */
static int parseargs(int argc, char *argv[])
{
	int i;
	const char *from_file = NULL;
	int ret = 0;

	opterr = 0;
	while ((i = getopt_long(argc, argv, PARSE_FLAGS, long_opts, NULL)) != -1) {
		switch (i) {

		case 'V':
			printf("pax-utils-%s: %s compiled %s\n%s\n"
			       "%s written for Gentoo by <solar, vapier and grobian @ gentoo.org>\n",
			       VERSION, __FILE__, __DATE__, rcsid, argv0);
			exit(EXIT_SUCCESS);
			break;
		case 'h': usage(EXIT_SUCCESS); break;
		case 'f':
			if (from_file) warn("You prob don't want to specify -f twice");
			from_file = optarg;
			break;
		case 'E':
			strncpy(match_etypes, optarg, sizeof(match_etypes));
			break;
		case 'M':
			match_bits = atoi(optarg);
			break;
		case 'O':
			if (sscanf(optarg, "%o", &match_perms) == -1)
				match_bits = 0;
			break;
		case 'o': {
			if (freopen(optarg, "w", stdout) == NULL)
				err("Could not open output stream '%s': %s", optarg, strerror(errno));
			break;
		}
		case 'N': {
			if (find_lib) warn("You prob don't want to specify -N twice");
			find_lib = optarg;
			break;
		}
		case 'F': {
			if (out_format) warn("You prob don't want to specify -F twice");
			out_format = optarg;
			break;
		}
		case 'Z': show_size = 1; break;
		case 'g': g_match = 1; break;
		case 'y': scan_symlink = 0; break;
		case 'A': scan_archives = 1; break;
		case 'C': color_init(true); break;
		case 'B': show_banner = 0; break;
		case 'p': scan_envpath = 1; break;
		case 'R': dir_recurse = 1; break;
		case 'm': dir_crossmount = 0; break;
		case 'n': show_needed = 1; break;
		case 'i': show_interp = 1; break;
		case 'b': show_bind = 1; break;
		case 'S': show_soname = 1; break;
		case 'q': be_quiet = 1; break;
		case 'v': be_verbose = (be_verbose % 20) + 1; break;
		case 'a': show_perms = show_endian = show_bind = 1; break;
		case 'D': show_endian = 1; break;
		case ':':
			err("Option '%c' is missing parameter", optopt);
		case '?':
			err("Unknown option '%c' or argument missing", optopt);
		default:
			err("Unhandled option '%c'; please report this", i);
		}
	}
	/* let the format option override all other options */
	if (out_format) {
		show_needed = show_interp = show_bind = show_soname = \
		show_perms = show_endian = show_size = 0;
		for (i = 0; out_format[i]; ++i) {
			if (!IS_MODIFIER(out_format[i])) continue;

			switch (out_format[++i]) {
			case '+': break;
			case '%': break;
			case '#': break;
			case 'F': break;
			case 'p': break;
			case 'f': break;
			case 'k': break;
			case 'N': break;
			case 'o': break;
			case 'a': break;
			case 'M': break;
			case 'Z': show_size = 1; break;
			case 'D': show_endian = 1; break;
			case 'O': show_perms = 1; break;
			case 'n': show_needed = 1; break;
			case 'i': show_interp = 1; break;
			case 'b': show_bind = 1; break;
			case 'S': show_soname = 1; break;
			default:
				err("Invalid format specifier '%c' (byte %i)",
				    out_format[i], i+1);
			}
		}

	/* construct our default format */
	} else {
		size_t fmt_len = 30;
		out_format = xmalloc(sizeof(char) * fmt_len);
		*out_format = '\0';
		if (!be_quiet)     xstrcat(&out_format, "%a ", &fmt_len);
		if (!be_quiet)     xstrcat(&out_format, "%o ", &fmt_len);
		if (show_perms)    xstrcat(&out_format, "%O ", &fmt_len);
		if (show_size)     xstrcat(&out_format, "%Z ", &fmt_len);
		if (show_endian)   xstrcat(&out_format, "%D ", &fmt_len);
		if (show_needed)   xstrcat(&out_format, "%n ", &fmt_len);
		if (show_interp)   xstrcat(&out_format, "%i ", &fmt_len);
		if (show_bind)     xstrcat(&out_format, "%b ", &fmt_len);
		if (show_soname)   xstrcat(&out_format, "%S ", &fmt_len);
		if (find_lib)      xstrcat(&out_format, "%N ", &fmt_len);
		if (!be_quiet)     xstrcat(&out_format, "%F ", &fmt_len);
	}
	if (be_verbose > 2) printf("Format: %s\n", out_format);

	/* now lets actually do the scanning */
	if (scan_envpath)
		scanmacho_envpath();
	if (!from_file && optind == argc && ttyname(0) == NULL && !scan_envpath)
		from_file = "-";
	if (from_file) {
		scanmacho_from_file(from_file);
		from_file = *argv;
	}
	if (optind == argc && !scan_envpath && !from_file)
		err("Nothing to scan !?");
	while (optind < argc) {
		search_path = argv[optind++];
		ret = scanmacho_dir(search_path);
	}

	return ret;
}
示例#7
0
static int scanmacho_fatobj(fatobj *fobj)
{
	unsigned long i;
	char found_needed, found_interp, found_soname, found_lib, found_file;
	static char *out_buffer = NULL;
	static size_t out_len;

	found_needed = found_interp = found_soname = \
	found_lib = found_file = 0;

	if (be_verbose > 2)
		printf("%s: scanning file {%s,%s}\n", fobj->filename,
		       get_machocputype(fobj),
		       get_machosubcputype(fobj));
	else if (be_verbose > 1)
		printf("%s: scanning file\n", fobj->filename);

	/* init output buffer */
	if (!out_buffer) {
		out_len = sizeof(char) * 80;
		out_buffer = xmalloc(out_len);
	}
	*out_buffer = '\0';

	/* show the header */
	if (!be_quiet && show_banner) {
		for (i = 0; out_format[i]; ++i) {
			if (!IS_MODIFIER(out_format[i])) continue;

			switch (out_format[++i]) {
			case '+': break;
			case '%': break;
			case '#': break;
			case 'F':
			case 'p':
			case 'f': prints("FILE "); found_file = 1; break;
			case 'o': prints("  TYPE   "); break;
			case 'M': prints("CPU "); break;
			case 'n': prints("NEEDED "); break;
			case 'i': prints("DYLINKER "); break;
			case 'b': prints("FLAGS "); break;
			case 'Z': prints("SIZE "); break;
			case 'S': prints("INSTALLNAME "); break;
			case 'N': prints("LIB "); break;
			case 'a': prints("ARCH "); break;
			case 'O': prints("PERM "); break;
			case 'D': prints("ENDIAN "); break;
			default: warnf("'%c' has no title ?", out_format[i]);
			}
		}
		if (!found_file) prints("FILE ");
		prints("\n");
		found_file = 0;
		show_banner = 0;
	}

	/* dump all the good stuff */
	for (i = 0; out_format[i]; ++i) {
		const char *out;
		const char *tmp;
		static char ubuf[sizeof(unsigned long)*2];
		if (!IS_MODIFIER(out_format[i])) {
			xchrcat(&out_buffer, out_format[i], &out_len);
			continue;
		}

		out = NULL;
		be_wewy_wewy_quiet = (out_format[i] == '#');
		be_semi_verbose = (out_format[i] == '+');
		switch (out_format[++i]) {
		case '+':
		case '%':
		case '#':
			xchrcat(&out_buffer, out_format[i], &out_len); break;
		case 'F':
			found_file = 1;
			if (be_wewy_wewy_quiet) break;
			xstrcat(&out_buffer, fobj->filename, &out_len);
			break;
		case 'p':
			found_file = 1;
			if (be_wewy_wewy_quiet) break;
			tmp = fobj->filename;
			if (search_path) {
				ssize_t len_search = strlen(search_path);
				ssize_t len_file = strlen(fobj->filename);
				if (!strncmp(fobj->filename, search_path, len_search) && \
				    len_file > len_search)
					tmp += len_search;
				if (*tmp == '/' && search_path[len_search-1] == '/') tmp++;
			}
			xstrcat(&out_buffer, tmp, &out_len);
			break;
		case 'f':
			found_file = 1;
			if (be_wewy_wewy_quiet) break;
			xstrcat(&out_buffer, fobj->base_filename, &out_len);
			break;
		case 'o': out = get_machomhtype(fobj); break;
		case 'M': out = get_machocputype(fobj); break;
		case 'D': out = get_machoendian(fobj); break;
		case 'O': out = strfileperms(fobj->filename); break;
		case 'n':
		case 'N': out = macho_file_needed_lib(fobj, &found_needed, &found_lib, (out_format[i]=='N'), &out_buffer, &out_len); break;
		case 'i': out = macho_file_interp(fobj, &found_interp); break;
		case 'b': get_machomhflags(fobj, &out_buffer, &out_len); break;
		case 'S': out = macho_file_soname(fobj, &found_soname); break;
		case 'a': out = get_machomtype(fobj); break;
		case 'Z': snprintf(ubuf, sizeof(ubuf), "%llu", (unsigned long long int)fobj->len); out = ubuf; break;;
		default: warnf("'%c' has no scan code?", out_format[i]);
		}
		if (out) {
			/* hack for comma delimited output like `scanelf -s sym1,sym2,sym3` */
			if (out_format[i] == 's' && (tmp=strchr(out,',')) != NULL)
				xstrncat(&out_buffer, out, &out_len, (tmp-out));
			else
				xstrcat(&out_buffer, out, &out_len);
		}
	}

#define FOUND_SOMETHING() \
	( found_needed || found_interp || found_soname || found_lib )

	if (!found_file && (!be_quiet || (be_quiet && FOUND_SOMETHING()))) {
		xchrcat(&out_buffer, ' ', &out_len);
		xstrcat(&out_buffer, fobj->filename, &out_len);
	}
	if (!be_quiet || (be_quiet && FOUND_SOMETHING())) {
		puts(out_buffer);
		fflush(stdout);
	}

	return 0;
}