drivers/accessibility/speakup/genmap.c

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

File Facts

System
Linux kernel
Corpus path
drivers/accessibility/speakup/genmap.c
Extension
.c
Size
3587 bytes
Lines
162
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

struct st_key_init {
	char *name;
	int value, shift;
};

static unsigned char key_data[MAXKEYVAL][16], *kp;

#include "mapdata.h"

static const char delims[] = "\t\n ";
static char *cp;
static int map_ver = 119; /* an arbitrary number so speakup can check */
static int shift_table[17];
static int max_states = 1, flags;
/* flags reserved for later, maybe for individual console maps */

static int get_shift_value(int state)
{
	int i;

	for (i = 0; shift_table[i] != state; i++) {
		if (shift_table[i] == -1) {
			if (i >= 16)
				oops("too many shift states", NULL);
			shift_table[i] = state;
			max_states = i+1;
		break;
	}
	}
	return i;
}

int
main(int argc, char *argv[])
{
	int value, shift_state, i, spk_val = 0, lock_val = 0;
	int max_key_used = 0, num_keys_used = 0;
	struct st_key *this;
	struct st_key_init *p_init;
	char buffer[256];

	bzero(key_table, sizeof(key_table));
	bzero(key_data, sizeof(key_data));

	shift_table[0] = 0;
	for (i = 1; i <= 16; i++)
		shift_table[i] = -1;

	if (argc < 2) {
		fputs("usage: genmap filename\n", stderr);
		exit(1);
	}

	for (p_init = init_key_data; p_init->name[0] != '.'; p_init++)
		add_key(p_init->name, p_init->value, p_init->shift);

	open_input(NULL, argv[1]);
	while (fgets(buffer, sizeof(buffer), infile)) {
		lc++;
		value = shift_state = 0;

		cp = strtok(buffer, delims);
		if (*cp == '#')
			continue;

		while (cp) {
			if (*cp == '=')
				break;
			this = find_key(cp);
			if (this == NULL)
				oops("unknown key/modifier", cp);
			if (this->shift == is_shift) {
				if (value)
					oops("modifiers must come first", cp);
				shift_state += this->value;
			} else if (this->shift == is_input)
				value = this->value;
			else
				oops("bad modifier or key", cp);
			cp = strtok(0, delims);
		}
		if (!cp)
			oops("no = found", NULL);

		cp = strtok(0, delims);
		if (!cp)
			oops("no speakup function after =", NULL);

		this = find_key(cp);
		if (this == NULL || this->shift != is_spk)

Annotation

Implementation Notes