Exemple #1
0
int keys_filter(
		enum io io_m,
		char *struc, unsigned n_ents,
		unsigned st_off, unsigned st_sz,
		int mode_off)
{
#define STRUCT_STR(i, st, off) *(const char **)(struc + i * st_sz + st_off)
	int ret = -1;

	bool potential[n_ents];

	if(mode_off >= 0){
		enum buf_mode curmode = windows_cur()->ui_mode;

		for(unsigned i = 0; i < n_ents; i++){
			enum buf_mode mode = *(enum buf_mode *)(
					struc + i * st_sz + mode_off);

			potential[i] = mode & curmode;
		}
	}else{
		memset(potential, true, sizeof potential);
	}

	unsigned ch_idx = 0;
	char *sofar = NULL;
	size_t nsofar = 0;
	for(;; ch_idx++){
		bool raw;
		int ch = io_getch(io_m, &raw, /*map:*/ch_idx == 0); /* dl shouldn't map l */
		if(raw){
			/* raw char, doesn't match any, get out */
			memset(potential, 0, sizeof potential);
		}

		sofar = urealloc(sofar, ++nsofar);
		sofar[nsofar-1] = ch;

		unsigned npotential = 0;
		unsigned last_potential = 0;

		for(unsigned i = 0; i < sizeof potential; i++){
			if(potential[i]){
				const char *const kstr = STRUCT_STR(i, struc, str_off);
				size_t keys_len = strlen(kstr);

				if(ch_idx >= keys_len || kstr[ch_idx] != ch){
					potential[i] = false;
				}else{
					npotential++;
					last_potential = i;
				}
			}
		}

		switch(npotential){
			case 1:
			{
				/* only accept once we have the full string */
				const char *kstr = STRUCT_STR(last_potential, struc, str_off);
				if(ch_idx == strlen(kstr) - 1){
					ret = last_potential;
					goto out;
				}
				break;
			}
			case 0:
				for(size_t i = nsofar; i > 0; i--)
					io_ungetch(sofar[i - 1], false);
				goto out;
		}
	}

out:
	free(sofar);
	return ret;
}
Exemple #2
0
		STRUCT_STR(version)
		STRUCT_STR(license)
		STRUCT_INT(versionnum)
		STRUCT_INT(numaudios)
		STRUCT_INT(numaudioengines)
		STRUCT_INT(nummidis)
		STRUCT_INT(numtimers)
		STRUCT_INT(numcards)
		STRUCT_INT(nummixers)
	FINISH
}

DEF(SNDCTL_MIXERINFO) {
	OSS_CALL(SNDCTL_MIXERINFO,oss_mixerinfo,STRUCT_SET(dev,GET_INT(2)),AS_STRUCT)
		STRUCT_INT(dev)
		STRUCT_STR(id)
		STRUCT_STR(name)
		STRUCT_INT(modify_counter)
		STRUCT_INT(enabled)
		STRUCT_INT(nrext)
		STRUCT_INT(priority)
		STRUCT_STR(devnode)
	FINISH
}

DEF(SNDCTL_MIX_EXTINFO) {
	OSS_CALL(SNDCTL_MIX_EXTINFO,oss_mixext,STRUCT_SET(dev,GET_INT(2)) STRUCT_SET(ctrl,GET_INT(3)),AS_STRUCT)
		STRUCT_INT(dev)
		STRUCT_INT(ctrl)
		STRUCT_INT(type)
		STRUCT_INT(maxvalue)