Example #1
0
File: _nk20.c Project: kevinarpe/kx
static PyObject*
_ktoarray(PyObject* self, PyObject* k)
{
	PyArrayObject *ret;
	if (!PyK_KCheck(k)) {
		return PyErr_Format(PyExc_TypeError, "not k object");
	}
	
	K kobj = ((PyK_K*)k)->kobj;
	if (!kobj) {
		return PyErr_Format(PyExc_AssertionError, "null kobj");
	}
	int t = kobj->t;
	/* XXX k objects of type 0 should be converted 
	 * to non-contiguous arrays rather than trigger
	 * an error.
	 */
	if (abs(t) >= LEN(types) && t != 5 ) {
		return PyErr_Format(PyExc_TypeError, 
				    "cannot create an array from a "
				    "k object of type %d", t);
	}
	int type = types[abs(t)]; /* PyArray type */
	int nd = t <= 0 || t == 5;          /* Number of dimensions (0 or 1) */
	int* d = &kobj->n;        /* Shape */
	char* data;
	switch (t) {
	case 1:
		data = (char*)&Ki(kobj);
		break;
	case 3:
		data = &Kc(kobj);
		break;
	case 4:
		data = Ks(kobj);
		break;
	default:
		data = KC(kobj);
	}
	/* Special handling for symbols arrays: convert data to Python strings */
	PyObject** buf = 0;
	if (t == -4) {
		int n = *d, i = 0;
		buf = (PyObject**)malloc(n * sizeof(PyObject*));
		for (i = 0; i < n; ++i) {
			char* s = KS(kobj)[i];
			if (!s) goto fail;
			buf[i] = PyString_FromString(s);
			if (!buf[i]) goto fail;
		}
		data = (char*)buf;
	} else if (t == 0 || t == 5) {
		int n = *d, i = 0;
		buf = (PyObject**)malloc(n * sizeof(PyObject*));
		for (i = 0; i < n; ++i) {
			K ki = KK(kobj)[i];
			if (!ki) goto fail;
			ci(ki);
			buf[i] = PyK_mk_K(ki);
			if (!buf[i]) {
				cd(ki);
				goto fail;
			}
		}
		data = (char*)buf;
	}
	if (!(ret = (PyArrayObject *)PyArray_FromDimsAndData(nd, d, type, data))) {
		goto fail;
	}
	if (buf) {
		ret->flags |= OWN_DATA;
	} else {
		Py_INCREF(k);
		ret->base = k;
	}
	return (PyObject*)ret;
 fail:
	if (buf) free(buf);
	return NULL;
}
Example #2
0
#endif

#define KC(n) KS_KEYCODE(n)

/*
 * 1f. US ASCII
 *
 * We use the same table for PS/2 and old HIL keyboards, as the only
 * differences are a few keys which are only present in one of both layouts,
 * and the one-function-only keypad in the old HIL flavour (hilkbd.c knows
 * about this and does The Right Thing).
 */

static const keysym_t hilkbd_keydesc_us[] = {
/*  pos      command		normal		shifted */
    KC(0),   KS_Cmd1,		KS_Control_R,
    KC(2),   KS_Cmd2,		KS_Mode_switch,	KS_Multi_key,
    KC(3),   KS_Cmd2,		KS_Alt_L,
    KC(4),			KS_Shift_R,
    KC(5),			KS_Shift_L,
    KC(6),   KS_Cmd1,		KS_Control_L,
    KC(7),   KS_Cmd_KbdReset,			/* Break/Reset */
    KC(8),			KS_KP_Left,	KS_KP_4,
    KC(9),			KS_KP_Up,	KS_KP_8,
    KC(10),			KS_KP_Begin,	KS_KP_5,
    KC(11),			KS_KP_Prior,	KS_KP_9,
    KC(12),			KS_KP_Right,	KS_KP_6,
    KC(13),			KS_KP_Home,	KS_KP_7,
    KC(14),			KS_KP_Separator,
    KC(15),			KS_KP_Enter,
    KC(16),			KS_KP_End,	KS_KP_1,
Example #3
0
File: _k20.c Project: kevinarpe/kx
/* XXX unfortunately API function gnk of which pyk.gk
   is based is a vararg function and therefore cannot
   be portably exported to Python. It would be better
   if libk20 supplied a function gnk_(I, K*)
   in addition to gnk(I,...) which would take an array
   of K objects as the second argument */
static PyObject*
_gk(PyObject* self, PyObject* args)
{
	int n = PyTuple_Size(args);
	if (!n) {
		return _mk_K(gtn(0,0));
	}
	int i, type = INT_MAX;
	K* ks = (K*)malloc(n*sizeof(K));
	K kobj;
	for(i = 0; i < n; i++) {
		K ki;
		int t;
		PyObject* argi = PyTuple_GET_ITEM(args, i);
		if (!IS_K(argi)) {
			goto fail;
		}
		ks[i] = ki = ((_K*)argi)->kobj;
		t = ki->t;
		if (INT_MAX == type) {
			type = t;
		} else if (t > 4 || t < 1 || t != type) {
			type = 0;
		}
	}
	kobj = gtn((type>0 && type<5)?-type:0, n);
	if (!kobj) {
		free(ks);
		return PyErr_Format(PyExc_TypeError, "gtn(%d,%d) returned null", -type, n);
	}
	switch (type) {
	case 1:
		for (i = 0; i < n; i++) {
			KI(kobj)[i] = Ki(ks[i]);
		}
		break;
	case 2:
		for (i = 0; i < n; i++) {
			KF(kobj)[i] = Kf(ks[i]);
		}
		break;
	case 3:
		for (i = 0; i < n; i++) {
			KC(kobj)[i] = Kc(ks[i]);
		}
		break;
	case 4:
		for (i = 0; i < n; i++) {
			KS(kobj)[i] = Ks(ks[i]);
		}
		break;
	default:
		memcpy(KK(kobj), ks, n*sizeof(K));
		for (i = 0; i < n; i++) {
			ci(ks[i]);
		}
		break;
	}
	free(ks);
	return _mk_K(kobj);
 fail:
	free(ks);
	PyErr_BadArgument();
	return NULL;
}
Example #4
0
/* $NetBSD: wskbdmap_lk201.c,v 1.6 2002/03/13 15:21:30 ad Exp $ */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wskbdmap_lk201.c,v 1.6 2002/03/13 15:21:30 ad Exp $");

#include <sys/types.h>
#include <dev/wscons/wsksymdef.h>
#include <dev/wscons/wsksymvar.h>
#include <dev/dec/wskbdmap_lk201.h>

#define KC(n) KS_KEYCODE((n) - MIN_LK201_KEY)

static const keysym_t lkkbd_keydesc_us[] = {
/*  pos      command		normal		shifted */
    KC(86),	KS_Cmd_Screen0,	KS_f1,
    KC(87),	KS_Cmd_Screen1,	KS_f2,
    KC(88),	KS_Cmd_Screen2,	KS_f3,
    KC(89),	KS_Cmd_Screen3,	KS_f4,
    KC(90),	KS_Cmd_Screen4,	KS_f5,
    KC(100),	KS_Cmd_Screen5,	KS_f6,
    KC(101),	KS_Cmd_Screen6,	KS_f7,
    KC(102),	KS_Cmd_Screen7,	KS_f8,
    KC(103),	KS_Cmd_Screen8,	KS_f9,
    KC(104),	KS_Cmd_Screen9,	KS_f10,
    KC(113),	KS_Cmd_Debugger,	KS_Escape, /* F11 */
    KC(114),			KS_f12,
    KC(115),			KS_f13,
    KC(116),			KS_f14,
    KC(124),			KS_Help,
    KC(125),	KS_Cmd,		KS_Execute,
    KC(128),			KS_f17,
Example #5
0
// sizeof the array, this would require extra checks in the code to prevent
// array out of bounds errors if the keyboard sent incorrect codes.  Since
// progmem is cheap and plentiful, a full array is used here to simplify the
// code.
//
// The second array maps two-byte make codes to KC_xxx values.  The first byte
// of the make codes is always 0xE0, so only the second byte is needed to map
// to a KC_xxx value.  The upper part of this array is also unused, but is
// included here for the same reason as the first array.

#define KC(x) PS2Keyboard::KC_##x
#define KCI KC(INVALID)

PROGMEM static const prog_uchar scanCodeToKeyCode[256] = {
  // 0x
  KCI,  KC(F9),    KCI, KC(F5), KC(F3),   KC(F1),          KC(F2), KC(F12),
  KCI, KC(F10), KC(F8), KC(F6), KC(F4),  KC(TAB),  KC(BACK_QUOTE), KCI,

  // 1x
  KCI, KC(LALT), KC(LSHFT),   KCI, KC(LCTRL), KC(Q), KC(1), KCI,
  KCI,      KCI,     KC(Z), KC(S),     KC(A), KC(W), KC(2), KCI,

  // 2x
  KCI,     KC(C), KC(X), KC(D), KC(E), KC(4), KC(3), KCI,
  KCI, KC(SPACE), KC(V), KC(F), KC(T), KC(R), KC(5), KCI,

  // 3x
  KCI, KC(N), KC(B), KC(H), KC(G), KC(Y), KC(6), KCI,
  KCI,   KCI, KC(M), KC(J), KC(U), KC(7), KC(8), KCI,

  // 4x
Example #6
0
 * partially.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wskbdmap_amiga.c,v 1.4 2002/01/28 09:57:04 aymeric Exp $");

#include <sys/types.h>
#include <dev/wscons/wsksymdef.h>
#include <dev/wscons/wsksymvar.h>
#include <dev/pckbc/wskbdmap_mfii.h>

#define KC(n) KS_KEYCODE(n)

static const keysym_t amikbd_keydesc_us[] = {
/*  pos      command		normal		shifted */
    KC(69),   KS_Cmd_Debugger,	KS_Escape,
    KC(1),                      KS_1,		KS_exclam,
    KC(2),                      KS_2,		KS_at,
    KC(3),                      KS_3,		KS_numbersign,
    KC(4),                      KS_4,		KS_dollar,
    KC(5),                      KS_5,		KS_percent,
    KC(6),                  	KS_6,		KS_asciicircum,
    KC(7),                 	KS_7,		KS_ampersand,
    KC(8),               	KS_8,		KS_asterisk,
    KC(9),                 	KS_9,		KS_parenleft,
    KC(10),                	KS_0,		KS_parenright,
    KC(11), 			KS_minus,	KS_underscore,
    KC(12), 			KS_equal,	KS_plus,
    KC(65),  KS_Cmd_ResetEmul,	KS_Delete,
    KC(66), 			KS_Tab,
    KC(16), 			KS_q,
Example #7
0
 * created by Juergen Hannken-Illjes.
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wskbdmap_mfii_rpc.c,v 1.1 2004/03/13 19:20:50 bjh21 Exp $");

#include <sys/types.h>
#include <dev/wscons/wsksymdef.h>
#include <dev/wscons/wsksymvar.h>
#include <arm/iomd/wskbdmap_mfii.h>

#define KC(n) KS_KEYCODE(n)

static const keysym_t rpckbd_keydesc_uk[] = {
/*  pos      command		normal		shifted		altgr		shift-altgr */
    KC(118), KS_Cmd_Debugger,	KS_Escape,

    KC(22),			KS_1,		KS_exclam,	KS_plusminus,	KS_exclamdown,
    KC(30),			KS_2,		KS_quotedbl,	KS_twosuperior,	KS_cent,
    KC(38),			KS_3,		KS_sterling,	KS_threesuperior,
    KC(37),			KS_4,		KS_dollar,	KS_acute,	KS_currency,
    KC(46),			KS_5,		KS_percent,	KS_mu,		KS_yen,
    KC(54),			KS_6,		KS_asciicircum,	KS_paragraph,
    KC(61),			KS_7,		KS_ampersand,	KS_periodcentered,
    KC(62),			KS_8,		KS_asterisk,	KS_cedilla,	KS_ordfeminine,
    KC(70),			KS_9,		KS_parenleft,	KS_onesuperior,	KS_diaeresis,
    KC(69),			KS_0,		KS_parenright,	KS_masculine,	KS_copyright,
    KC(78),			KS_minus,	KS_underscore,	KS_hyphen,	KS_ssharp,
    KC(85),			KS_equal,	KS_plus,	KS_onehalf,	KS_guillemotleft,
    KC(14),			KS_grave,	KS_notsign,	KS_brokenbar,
    KC(102), KS_Cmd_ResetEmul,	KS_Delete,
 */

#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: wskbdmap_sun.c,v 1.17 2010/01/14 02:18:59 macallan Exp $");

#include <sys/types.h>
#include <dev/wscons/wsksymdef.h>
#include <dev/wscons/wsksymvar.h>

#include "opt_sunkbd.h"

#define KC(n) KS_KEYCODE(n)

static const keysym_t wssun_keydesctab_us [] = {
/*  pos      command			normal		shifted */
    KC(0x01), KS_Cmd,
    KC(0x02), KS_Cmd_VolumeDown,
    KC(0x03),				KS_Again,
    KC(0x04), KS_Cmd_VolumeUp,
    KC(0x05), KS_Cmd_Screen0,				KS_f1,
    KC(0x06), KS_Cmd_Screen1,				KS_f2,
    KC(0x07), KS_Cmd_Screen9,				KS_f10,
    KC(0x08), KS_Cmd_Screen2,				KS_f3,
    KC(0x09),				KS_f11,
    KC(0x0a), KS_Cmd_Screen3,				KS_f4,
    KC(0x0b),				KS_f12,
    KC(0x0c), KS_Cmd_Screen4,				KS_f5,
    KC(0x0d),				KS_Alt_R,
    KC(0x0e), KS_Cmd_Screen5,				KS_f6,
    KC(0x10), KS_Cmd_Screen6,				KS_f7,
    KC(0x11), KS_Cmd_Screen7,				KS_f8,
Example #9
0
Z K gpn_(S s, I i) {K z=gtn(-3,i); memcpy(KC(z),s,i); R z; }