drivers/accessibility/speakup/i18n.c

Source file repositories/reference/linux-study-clean/drivers/accessibility/speakup/i18n.c

File Facts

System
Linux kernel
Corpus path
drivers/accessibility/speakup/i18n.c
Extension
.c
Size
19342 bytes
Lines
631
Domain
Driver Families
Bucket
drivers/accessibility
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (next_percent) {
			/* skip over doubled percent signs */
			while (next_percent[0] == '%' &&
			       next_percent[1] == '%')
				next_percent += 2;
			if (*next_percent == '%')
				found = 1;
			else if (*next_percent == '\0')
				next_percent = NULL;
		}
	}

	return next_percent;
}

/* Skip over 0 or more flags. */
static char *skip_flags(char *input)
{
	while ((*input != '\0') && strchr(" 0+-#", *input))
		input++;
	return input;
}

/* Skip over width.precision, if it exists. */
static char *skip_width(char *input)
{
	while (isdigit(*input))
		input++;
	if (*input == '.') {
		input++;
		while (isdigit(*input))
			input++;
	}
	return input;
}

/*
 * Skip past the end of the conversion part.
 * Note that this code only accepts a handful of conversion specifiers:
 * c d s x and ld.  Not accidental; these are exactly the ones used in
 * the default group of formatted messages.
 */
static char *skip_conversion(char *input)
{
	if ((input[0] == 'l') && (input[1] == 'd'))
		input += 2;
	else if ((*input != '\0') && strchr("cdsx", *input))
		input++;
	return input;
}

/*
 * Function: find_specifier_end
 * Return a pointer to the end of the format specifier.
 */
static char *find_specifier_end(char *input)
{
	input++;		/* Advance over %. */
	input = skip_flags(input);
	input = skip_width(input);
	input = skip_conversion(input);
	return input;
}

/*
 * Function: compare_specifiers
 * Compare the format specifiers pointed to by *input1 and *input2.
 * Return true if they are the same, false otherwise.
 * Advance *input1 and *input2 so that they point to the character following
 * the end of the specifier.
 */
static bool compare_specifiers(char **input1, char **input2)
{
	bool same = false;
	char *end1 = find_specifier_end(*input1);
	char *end2 = find_specifier_end(*input2);
	size_t length1 = end1 - *input1;
	size_t length2 = end2 - *input2;

	if ((length1 == length2) && !memcmp(*input1, *input2, length1))
		same = true;

	*input1 = end1;
	*input2 = end2;
	return same;
}

/*
 * Function: fmt_validate
 * Check that two format strings contain the same number of format specifiers,

Annotation

Implementation Notes