<commit_before>/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <fcntl.h>
#include <linux/input.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <libudev.h>
#include <regex.h>

#include "cras_util.h"
#include "cras_gpio_jack.h"

int gpio_switch_open(const char *pathname)
{
	return open(pathname, O_RDONLY);
}

int gpio_switch_read(int fd, void *buf, size_t n_bytes)
{
	return read(fd, buf, n_bytes);
}

int gpio_switch_eviocgname(int fd, char *name, size_t n_bytes)
{
	return ioctl(fd, EVIOCGNAME(n_bytes), name);
}

int gpio_switch_eviocgbit(int fd, unsigned long sw, void *buf)
{
	return ioctl(fd, EVIOCGBIT(EV_SW, sw + 1), buf);
}

int gpio_switch_eviocgsw(int fd, void *bits, size_t n_bytes)
{
	return ioctl(fd, EVIOCGSW(n_bytes), bits);
}

static void compile_regex(regex_t *regex, const char *str)
{
	int r;
	r = regcomp(regex, str, REG_EXTENDED);
	assert(r == 0);
}

static unsigned is_microphone_jack(const char *name)
{
	regmatch_t m[1];
	regex_t regex;
	unsigned success;
	const char *re = "^.*(Mic|Headphone) Jack$";

	compile_regex(&regex, re);
	success = regexec(&regex, name, ARRAY_SIZE(m), m, 0) == 0;
	regfree(&regex);
	return success;
}

static unsigned is_headphone_jack(const char *name)
{
	regmatch_t  m[1];
	regex_t	    regex;
	unsigned    success;
	const char *re = "^.*Headphone Jack$";

	compile_regex(&regex, re);
	success = regexec(&regex, name, ARRAY_SIZE(m), m, 0) == 0;
	regfree(&regex);<commit_msg>CRAS: gpio jack - Input jacks can't detect "Headphone Jack".<commit_after>/* Copyright (c) 2012 The Chromium OS Authors. All rights reserved.
 * Use of this source code is governed by a BSD-style license that can be
 * found in the LICENSE file.
 */

#include <fcntl.h>
#include <linux/input.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <unistd.h>
#include <libudev.h>
#include <regex.h>

#include "cras_util.h"
#include "cras_gpio_jack.h"

int gpio_switch_open(const char *pathname)
{
	return open(pathname, O_RDONLY);
}

int gpio_switch_read(int fd, void *buf, size_t n_bytes)
{
	return read(fd, buf, n_bytes);
}

int gpio_switch_eviocgname(int fd, char *name, size_t n_bytes)
{
	return ioctl(fd, EVIOCGNAME(n_bytes), name);
}

int gpio_switch_eviocgbit(int fd, unsigned long sw, void *buf)
{
	return ioctl(fd, EVIOCGBIT(EV_SW, sw + 1), buf);
}

int gpio_switch_eviocgsw(int fd, void *bits, size_t n_bytes)
{
	return ioctl(fd, EVIOCGSW(n_bytes), bits);
}

static void compile_regex(regex_t *regex, const char *str)
{
	int r;
	r = regcomp(regex, str, REG_EXTENDED);
	assert(r == 0);
}

static unsigned is_microphone_jack(const char *name)
{
	regmatch_t m[1];
	regex_t regex;
	unsigned success;
	const char *re = "^.*Mic Jack$";

	compile_regex(&regex, re);
	success = regexec(&regex, name, ARRAY_SIZE(m), m, 0) == 0;
	regfree(&regex);
	return success;
}

static unsigned is_headphone_jack(const char *name)
{
	regmatch_t  m[1];
	regex_t	    regex;
	unsigned    success;
	const char *re = "^.*Headphone Jack$";

	compile_regex(&regex, re);
	success = regexec(&regex, name, ARRAY_SIZE(m), m, 0) == 0;
	regfree(&regex);
{'fraction_non_alphanumeric': 0.14086640411996365, 'fraction_numerical': 0.007270524083611027, 'mean_word_length': 5.003636363636364, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, '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': '5373489', 'n_tokens_mistral': 1344, 'n_tokens_neox': 1318, 'n_words': 357}