<commit_before>/*
 * Read value from GPIO line.
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 */

#include <gpiod.h>
#include "tools-common.h"

#include <stdio.h>
#include <string.h>
#include <getopt.h>

static const struct option longopts[] = {
	{ "help",	no_argument,	NULL,	'h' },
	{ "version",	no_argument,	NULL,	'v' },
	{ 0 },
};

static const char *const shortopts = "+hv";

static void print_help(void)
{
	printf("Usage: %s [OPTIONS] <name>\n", get_progname());
	printf("Find a GPIO line by name. The output of this command can be used as input for gpioget/set.\n");
	printf("Options:\n");
	printf("  -h, --help:\t\tdisplay this message and exit\n");
	printf("  -v, --version:\tdisplay the version and exit\n");
}

int main(int argc, char **argv)
{
	struct gpiod_line *line;
	struct gpiod_chip *chip;
	int optc, opti;

	set_progname(argv[0]);

	for (;;) {
		optc = getopt_long(argc, argv, shortopts, longopts, &opti);
		if (optc < 0)
			break;

		switch (optc) {
		case 'h':
			print_help();
			return EXIT_SUCCESS;
		case 'v':
			print_version();
			return EXIT_SUCCESS;
		case '?':
			die("try %s --help", get_progname());
		default:
			abort();
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 1)
		die("GPIO line name must be specified");

	line = gpiod_line_find_by_name(argv[0]);
	if (!line)
		return EXIT_FAILURE;

	chip = gpiod_line_get_chip(line);

	printf("%s %u\n", gpiod_chip_name(chip), gpiod_line_offset(line));

	gpiod_chip_close(chip);

	return EXIT_SUCCESS;
}
<commit_msg>gpiofind: tweak the error message on invalid arguments<commit_after>/*
 * Read value from GPIO line.
 *
 * Copyright (C) 2017 <NAME> <<EMAIL>>
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms of version 2.1 of the GNU Lesser General Public License
 * as published by the Free Software Foundation.
 */

#include <gpiod.h>
#include "tools-common.h"

#include <stdio.h>
#include <string.h>
#include <getopt.h>

static const struct option longopts[] = {
	{ "help",	no_argument,	NULL,	'h' },
	{ "version",	no_argument,	NULL,	'v' },
	{ 0 },
};

static const char *const shortopts = "+hv";

static void print_help(void)
{
	printf("Usage: %s [OPTIONS] <name>\n", get_progname());
	printf("Find a GPIO line by name. The output of this command can be used as input for gpioget/set.\n");
	printf("Options:\n");
	printf("  -h, --help:\t\tdisplay this message and exit\n");
	printf("  -v, --version:\tdisplay the version and exit\n");
}

int main(int argc, char **argv)
{
	struct gpiod_line *line;
	struct gpiod_chip *chip;
	int optc, opti;

	set_progname(argv[0]);

	for (;;) {
		optc = getopt_long(argc, argv, shortopts, longopts, &opti);
		if (optc < 0)
			break;

		switch (optc) {
		case 'h':
			print_help();
			return EXIT_SUCCESS;
		case 'v':
			print_version();
			return EXIT_SUCCESS;
		case '?':
			die("try %s --help", get_progname());
		default:
			abort();
		}
	}

	argc -= optind;
	argv += optind;

	if (argc != 1)
		die("exactly one GPIO line name must be specified");

	line = gpiod_line_find_by_name(argv[0]);
	if (!line)
		return EXIT_FAILURE;

	chip = gpiod_line_get_chip(line);

	printf("%s %u\n", gpiod_chip_name(chip), gpiod_line_offset(line));

	gpiod_chip_close(chip);

	return EXIT_SUCCESS;
}

{'fraction_non_alphanumeric': 0.15311143270622288, 'fraction_numerical': 0.006367583212735167, 'mean_word_length': 3.9371428571428573, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 19, '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': '7208514', 'n_tokens_mistral': 1374, 'n_tokens_neox': 1278, 'n_words': 383}