#ifndef lint static char sccsid[] = "@(#)Xparse.c 9.2 88/01/19 Copyright 1987 Sun Micro"; #endif /* * Copyright (c) 1987 by Sun Microsystems, Inc. */ /*- Xparse.c Xparse.c, Fri Apr 25 16:23:05 1986 David Rosenthal, Sun Microsystems */ /* * TODO: XXX * * - add stack overflow and underflow checking to d_* and e_* routines. * - revamp all of the d_* and e_* routines and have a single routine * that is parameterized to take all combinations (?) * - Change floorfr() to roundfr()? Already done in e_shorts. */ #ifdef REF #include #include #endif #include "PostScript.h" #include "X.h" #include "Xproto.h" extern char *snoopalloc(); /* * These functions decode the data in an Xreq according to the * types implicit in the op-code. The types are: * a internet address * b byte, used for * l long, used for resource id, locator, event mask * s short * u unsigned short, used for pixel, r, g, or b, plane mask * number of color map cells */ static int d_a(ee, xr) register struct execution_environment *ee; register XReq *xr; { /* XXX - do something here */ return (0); } static int d_l(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.l[0])); ee->optop++; return (0); } static int d_ll(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.l[0])); optop++; set_fixed_object(optop, fracti(xr->param.l[1])); ee->optop += 2; return (0); } static int d_ls(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.s[2])); optop++; set_fixed_object(optop, fracti(xr->param.l[0])); ee->optop += 2; return (0); } static int d_lsssu(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.u[5])); optop++; set_fixed_object(optop, fracti(xr->param.s[4])); optop++; set_fixed_object(optop, fracti(xr->param.s[3])); optop++; set_fixed_object(optop, fracti(xr->param.s[2])); optop++; set_fixed_object(optop, fracti(xr->param.l[0])); ee->optop += 5; return (0); } static int d_luu(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.u[3])); optop++; set_fixed_object(optop, fracti(xr->param.u[2])); optop++; set_fixed_object(optop, fracti(xr->param.l[0])); ee->optop += 3; return (0); } static int d_luulss(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.s[7])); optop++; set_fixed_object(optop, fracti(xr->param.s[6])); optop++; set_fixed_object(optop, fracti(xr->param.l[2])); optop++; set_fixed_object(optop, fracti(xr->param.u[3])); optop++; set_fixed_object(optop, fracti(xr->param.u[2])); optop++; set_fixed_object(optop, fracti(xr->param.l[0])); ee->optop += 6; return (0); } static int d_p(ee, xr) register struct execution_environment *ee; register XReq *xr; { d_l(ee, xr); } static int d_s(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.s[0])); ee->optop++; return (0); } static int d_ss(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.s[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[0])); ee->optop += 2; return (0); } static int d_sslssss(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; register int i = 0; set_fixed_object(optop, fracti(xr->param.s[7])); optop++; set_fixed_object(optop, fracti(xr->param.s[6])); optop++; set_fixed_object(optop, fracti(xr->param.s[5])); optop++; set_fixed_object(optop, fracti(xr->param.s[4])); optop++; set_fixed_object(optop, fracti(xr->param.l[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[0])); ee->optop += 7; return (0); } static int d_sslusbb(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.b[13])); optop++; set_fixed_object(optop, fracti(xr->param.b[12])); optop++; set_fixed_object(optop, fracti(xr->param.s[5])); optop++; set_fixed_object(optop, fracti(xr->param.u[4])); optop++; set_fixed_object(optop, fracti(xr->param.l[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[0])); ee->optop += 7; return (0); } static int d_ssluusbb(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.b[15])); optop++; set_fixed_object(optop, fracti(xr->param.b[14])); optop++; set_fixed_object(optop, fracti(xr->param.s[6])); optop++; set_fixed_object(optop, fracti(xr->param.u[5])); optop++; set_fixed_object(optop, fracti(xr->param.u[4])); optop++; set_fixed_object(optop, fracti(xr->param.l[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[0])); ee->optop += 8; return (0); } static int d_ssss(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.s[3])); optop++; set_fixed_object(optop, fracti(xr->param.s[2])); optop++; set_fixed_object(optop, fracti(xr->param.s[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[0])); ee->optop += 4; return (0); } static int d_ssssll(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.l[3])); optop++; set_fixed_object(optop, fracti(xr->param.l[2])); ee->optop += 2; d_ssss(ee, xr); return (0); } static int d_sssslss(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.s[7])); optop++; set_fixed_object(optop, fracti(xr->param.s[6])); optop++; set_fixed_object(optop, fracti(xr->param.l[2])); ee->optop += 3; d_ssss(ee, xr); return (0); } static int d_sssssl(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.l[3])); optop++; set_fixed_object(optop, fracti(xr->param.s[4])); ee->optop += 2; d_ssss(ee, xr); return (0); } static int d_ssssss(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.s[5])); optop++; set_fixed_object(optop, fracti(xr->param.s[4])); ee->optop += 2; d_ssss(ee, xr); return (0); } static int d_ssssubb(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.b[11])); optop++; set_fixed_object(optop, fracti(xr->param.b[10])); optop++; set_fixed_object(optop, fracti(xr->param.u[4])); ee->optop += 3; d_ssss(ee, xr); return (0); } static int d_ssssul(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.l[3])); optop++; set_fixed_object(optop, fracti(xr->param.u[4])); ee->optop += 2; d_ssss(ee, xr); return (0); } static int d_ssssuul(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.l[3])); optop++; set_fixed_object(optop, fracti(xr->param.u[5])); optop++; set_fixed_object(optop, fracti(xr->param.u[4])); ee->optop += 3; d_ssss(ee, xr); return (0); } static int d_subbsusss(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.s[7])); optop++; set_fixed_object(optop, fracti(xr->param.s[6])); optop++; set_fixed_object(optop, fracti(xr->param.s[5])); optop++; set_fixed_object(optop, fracti(xr->param.u[4])); optop++; set_fixed_object(optop, fracti(xr->param.s[3])); optop++; set_fixed_object(optop, fracti(xr->param.b[5])); optop++; set_fixed_object(optop, fracti(xr->param.b[4])); optop++; set_fixed_object(optop, fracti(xr->param.u[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[0])); ee->optop += 9; return (0); } static int d_sul(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.l[1])); optop++; set_fixed_object(optop, fracti(xr->param.u[1])); optop++; set_fixed_object(optop, fracti(xr->param.s[0])); ee->optop += 3; return (0); } static int d_u(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.u[0])); optop++; ee->optop += 1; return (0); } static int d_uuu(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->param.u[2])); optop++; set_fixed_object(optop, fracti(xr->param.u[1])); optop++; set_fixed_object(optop, fracti(xr->param.u[0])); ee->optop += 3; return (0); } /* * Returns the number of bytes of valid data to follow this XReq * NB - actual number of bytes is this rounded up to multiple of 4 */ static unsigned BytesOfData(xr) register XReq *xr; { register unsigned ret = 0; #ifdef notdef extern int depth; /* No. of planes of display on this stream */ #else int depth = 1; #endif /* notdef */ switch (xr->code) { case X_StoreName: case X_GetFont: case X_CharWidths: case X_StoreBytes: case X_LookupColor: ret = xr->param.s[0] * sizeof (char); break; case X_Draw: case X_DrawFilled: ret = xr->param.s[0] * sizeof (Vertex); break; case X_FreeColors: ret = xr->param.s[0] * sizeof (short); break; case X_StoreColors: ret = xr->param.s[0] * sizeof (ColorDef); break; case X_StringWidth: ret = xr->param.s[2] * sizeof (char); break; case X_Text: case X_TextMask: ret = xr->param.s[6] * sizeof (char); break; case X_PixmapBitsPut: if (xr->param.s[4] == 0) { /* XY format */ ret = ((xr->param.s[1] + 15) / 16) * xr->param.s[0] * 2*depth; } else { /* Z format */ ret = xr->param.s[1] * xr->param.s[0]; if (depth >=9 && depth <= 16) ret *= 2; } break; case X_StorePixmap: if (xr->param.s[4] == 0) { /* XY format */ ret = ((xr->param.s[1] + 15) / 16) * xr->param.s[0] * 2*depth; } else { /* Z format */ ret = xr->param.s[1] * xr->param.s[0]; if (depth >=9 && depth <= 16) ret *= 2; } break; case X_BitmapBitsPut: case X_StoreBitmap: ret = ((xr->param.s[1] + 15) / 16) * xr->param.s[0] * 2; break; } return(ret); } /* * These functions decode the data that follows some Xreq-s * according to the implicit type. The "n" arg is the size of * the valid data in bytes (i.e. not rounded up) */ #ifdef notdef static int d_bitmap(ee) register struct execution_environment *ee; { /* returns a string */ return (0); } #else #define d_bitmap NULL #endif static int d_colordefs(ee) register struct execution_environment *ee; { register ColorDef *cd; register int i; register struct object *or, *og, *ob, *op; register struct object *optop = ee->optop - 1; struct body *pr, *pg, *pb, *pp; if (optop->type != string_type) { ee->error_code = typecheck_error_code; return (0); } i = optop->value.substring.length / sizeof (ColorDef); cd = (ColorDef *) (body_of(optop)->body.string.chars + optop->value.substring.start); /* return four arrays - r, g, b, and pixels */ pr = new_array_body(i); or = pr->body.array.objects; pg = new_array_body(i); og = pg->body.array.objects; pb = new_array_body(i); ob = pb->body.array.objects; pp = new_array_body(i); op = pp->body.array.objects; while (i--) { set_typed_object(or, fixed_type); or->value.fixed = fracti(cd->red); or++; set_typed_object(og, fixed_type); og->value.fixed = fracti(cd->green); og++; set_typed_object(ob, fixed_type); ob->value.fixed = fracti(cd->blue); ob++; set_typed_object(op, fixed_type); op->value.fixed = fracti(cd->pixel); op++; cd++; } ee->optop--; object_decref(optop); set_typed_bodied_object(ee->optop++, array_type, pr); set_typed_bodied_object(ee->optop++, array_type, pg); set_typed_bodied_object(ee->optop++, array_type, pb); set_typed_bodied_object(ee->optop++, array_type, pp); } static int d_colors(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop - 1; register int i; register struct object *o; register unsigned short *cl; struct body *p; /* return an array */ i = optop->value.substring.length; cl = (unsigned short *)(body_of(optop)->body.string.chars + optop->value.substring.start); p = new_array_body(i); o = p->body.array.objects; while (i--) { set_typed_object(o, fixed_type); o->value.fixed = fracti(*cl++); o++; } object_decref(optop); set_typed_bodied_object(optop, array_type, p); } #ifdef notdef static int d_pixmap(ee) register struct execution_environment *ee; { /* returns a string */ return (0); } #else #define d_pixmap NULL #endif static int d_string(ee) register struct execution_environment *ee; { register int i; register struct object *optop = ee->optop - 1; if (optop->type != string_type) { ee->error_code = typecheck_error_code; return (0); } /* its already a string! */ } static int d_vertices(ee) register struct execution_environment *ee; { register Vertex *vt; register int i; register struct object *oa; register struct object *optop = ee->optop - 1; struct body *pa; if (optop->type != string_type) { ee->error_code = typecheck_error_code; return (0); } i = optop->value.substring.length / sizeof (Vertex); vt = (Vertex *) (body_of(optop)->body.string.chars + optop->value.substring.start); /* return an array with x, y, flags for i vertices - [x, y, f, ...] */ pa = new_array_body(i*3); oa = pa->body.array.objects; pa->body.array.used = i * 3; while (i--) { set_typed_object(oa, fixed_type); oa->value.fixed = fracti(vt->x); oa++; set_typed_object(oa, fixed_type); oa->value.fixed = fracti(vt->y); oa++; set_typed_object(oa, fixed_type); oa->value.fixed = fracti(vt->flags); oa++; vt++; } object_decref(optop); set_typed_bodied_object(optop, array_type, pa); optop->value.substring.start = 0; optop->value.substring.length = pa->body.array.size; } /* * These functions collect the data appropriate to an XRep * for a particular function and pack it into the struct * They all expect the following stack: * - code Reply Code * - params The set of parameters */ static int e_(ee, xr) /* encodes nothing */ register struct execution_environment *ee; register XRep *xr; { return (1); } static int e_l(ee, xr) register struct execution_environment *ee; register XRep *xr; { register struct object *optop = ee->optop - 1; if (optop->type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.l[0] = floorfr(optop->value.fixed); ee->optop -= 1; return (1); } static int e_lbbbl(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 5; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) if ( optop[-i].type != fixed_type ) { ee->error_code = typecheck_error_code; return( 0 ); } xr->param.l[0] = floorfr(optop[-1].value.fixed); xr->param.b[4] = floorfr(optop[-2].value.fixed); xr->param.b[5] = floorfr(optop[-3].value.fixed); xr->param.b[6] = floorfr(optop[-4].value.fixed); xr->param.l[2] = floorfr(optop[-5].value.fixed); return( 1 ); } static int e_ll(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 2; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) { if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.l[i] = floorfr(optop[-i].value.fixed); } return (1); } static int e_lsl(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 3; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.l[0] = floorfr(optop[0].value.fixed); xr->param.s[2] = floorfr(optop[-1].value.fixed); xr->param.l[3] = floorfr(optop[-2].value.fixed); return (1); } static int e_lss(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 3; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.l[0] = floorfr(optop[0].value.fixed); xr->param.s[2] = floorfr(optop[-1].value.fixed); xr->param.s[3] = floorfr(optop[-2].value.fixed); return (1); } static int e_lsss(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 4; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.l[0] = floorfr(optop[0].value.fixed); xr->param.s[2] = floorfr(optop[-1].value.fixed); xr->param.s[3] = floorfr(optop[-2].value.fixed); xr->param.s[4] = floorfr(optop[-3].value.fixed); return (1); } static int e_lssslss(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 7; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.l[0] = floorfr(optop[0].value.fixed); xr->param.s[3] = floorfr(optop[-1].value.fixed); xr->param.s[4] = floorfr(optop[-2].value.fixed); xr->param.s[5] = floorfr(optop[-3].value.fixed); xr->param.l[3] = floorfr(optop[-4].value.fixed); xr->param.s[8] = floorfr(optop[-5].value.fixed); xr->param.s[9] = floorfr(optop[-6].value.fixed); return (1); } static int e_lssssll(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 7; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.l[0] = floorfr(optop[0].value.fixed); xr->param.s[2] = floorfr(optop[-1].value.fixed); xr->param.s[3] = floorfr(optop[-2].value.fixed); xr->param.s[4] = floorfr(optop[-3].value.fixed); xr->param.s[5] = floorfr(optop[-4].value.fixed); xr->param.l[3] = floorfr(optop[-5].value.fixed); xr->param.l[4] = floorfr(optop[-6].value.fixed); return (1); } static int e_lsssu(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 5; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.l[0] = floorfr(optop[0].value.fixed); xr->param.s[2] = floorfr(optop[-1].value.fixed); xr->param.s[3] = floorfr(optop[-2].value.fixed); xr->param.s[4] = floorfr(optop[-3].value.fixed); xr->param.u[5] = floorfr(optop[-4].value.fixed); /* XXX # cells */ return (1); } static int e_s(ee, xr) register struct execution_environment *ee; register XRep *xr; { register struct object *optop = ee->optop - 1; if (optop->type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.s[0] = floorfr(optop->value.fixed); ee->optop -= 1; return (1); } static int e_ss(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 2; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) { if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.s[i] = floorfr(optop[-i].value.fixed); } return (1); } static int e_ssss(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 4; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) { if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.s[i] = floorfr(optop[-i].value.fixed); } return (1); } static int e_sssssbbl(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 8; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) { if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } switch (i) { case 7: xr->param.l[3] = floorfr(optop[-i].value.fixed); break; case 6: xr->param.b[11] = floorfr(optop[-i].value.fixed); break; case 5: xr->param.b[12] = floorfr(optop[-i].value.fixed); break; default: xr->param.s[i] = floorfr(optop[-i].value.fixed); break; } } return (1); } static int e_ssssss(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 6; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) { if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.s[i] = floorfr(optop[-i].value.fixed); } return (1); } static int e_u(ee, xr) register struct execution_environment *ee; register XRep *xr; { register struct object *optop = ee->optop - 1; if (optop->type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.u[0] = (unsigned short) floorfr(optop->value.fixed); ee->optop -= 1; return (1); } static int e_uuu(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 3; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) { if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.u[i] = (unsigned short) floorfr(optop[-i].value.fixed); } return (1); } static int e_uuuuuu(ee, xr) register struct execution_environment *ee; register XRep *xr; { register unsigned i = 6; register struct object *optop; optop = ee->optop; ee->optop -= i; optop--; while (i--) { if (optop[-i].type != fixed_type) { ee->error_code = typecheck_error_code; return (0); } xr->param.u[i] = (unsigned short) floorfr(optop[-i].value.fixed); } return (1); } /* * These functions collect the data that follows some XRep-s * and send it out. */ static int e_hosts(ee, xr, sp) register struct execution_environment *ee; register XRep *xr; char **sp; { return (NULL); /* XXX */ } static int e_pixmap(ee, xr, sp) register struct execution_environment *ee; register XRep *xr; char **sp; { return (NULL); /* XXX */ } /* Takes an array of numbers and packs it into a string, with proper * padding */ /***** static int e_shorts(ee, xr, sp) register struct execution_environment *ee; register XRep *xr; short **sp; { register struct object *optop = ee->optop - 1; register short *ret, *s; register unsigned i; register struct object *o; if (optop->type != array_type) { ee->error_code = typecheck_error_code; return (NULL); } *sp = s = ret = (short *)snoopalloc("Xparse.c", optop->value.substring.length * sizeof (short)); o = body_of(optop)->body.array.objects+optop->value.substring.start; i = optop->value.substring.length; while (i--) { *s++ = (o->type != fixed_type ? 0 : floorfr(o->value.fixed)); o++; } ee->optop--; return (optop->value.substring.length); } *****/ static int e_shorts( ee ) register struct execution_environment *ee; { register struct object *optop = ee->optop; register struct object *p; register char *s; struct object data; int count, size; if ( optop[-1].type != array_type ) { ee->error_code = typecheck_error_code; return( 0 ); } count = optop[-1].value.substring.length; size = count*2; if ( size%4 ) size += 2; /* pad to multiple of 4 */ data = make_string(size, 0); s = body_of(&data)->body.string.chars; /* start of string */ bzero( s, size ); p = body_of(optop-1)->body.array.objects + optop[-1].value.substring.start; /* first obj in array */ while ( count-- ) { if ( p->type != fixed_type ) { ee->error_code = typecheck_error_code; return; } *((short *)s) = (short)roundfr( p->value.fixed ); s += sizeof(short); p++; } object_decref(optop-1); optop[-1] = data; return( count ); } static int e_string(ee, xr, sp) register struct execution_environment *ee; register XRep *xr; char **sp; { register struct object *optop = ee->optop - 1; register char *ret; if (optop->type != string_type) { ee->error_code = typecheck_error_code; return (NULL); } *sp = ret = snoopalloc("Xparse.c", optop->value.substring.length); bcopy(ret, body_of(optop)->body.string.chars+optop->value.substring.start, optop->value.substring.length); ee->optop--; return (optop->value.substring.length); } #define e_colors e_shorts /* * SWM: code 0 is an error reply. */ static struct Xop { char *Xopname; int (*Xparam)(); int (*Xpdata)(); int (*Xreply)(); int (*Xrdata)(); } XopTable[] = { "X Error Reply", NULL, NULL, e_lbbbl, NULL, "X_CreateWindow", d_ssssll, NULL, e_l, NULL, "X_CreateTransparency", d_ssss, NULL, e_l, NULL, "X_DestroyWindow", NULL, NULL, NULL, NULL, "X_DestroySubwindows", NULL, NULL, NULL, NULL, "X_MapWindow", NULL, NULL, NULL, NULL, "X_MapSubwindows", NULL, NULL, NULL, NULL, "X_UnmapWindow", NULL, NULL, NULL, NULL, "X_UnmapSubwindows", NULL, NULL, NULL, NULL, "X_UnmapTransparent", NULL, NULL, NULL, NULL, "X_RaiseWindow", NULL, NULL, NULL, NULL, "X_LowerWindow", NULL, NULL, NULL, NULL, "X_CircWindowUp", NULL, NULL, NULL, NULL, "X_MoveWindow", d_ss, NULL, NULL, NULL, "X_ChangeWindow", d_ss, NULL, NULL, NULL, "X_ConfigureWindow", d_ssss, NULL, NULL, NULL, "X_ChangeBackground", d_l, NULL, NULL, NULL, "X_ChangeBorder", d_l, NULL, NULL, NULL, "X_TileMode", NULL, NULL, NULL, NULL, "X_ClipMode", NULL, NULL, NULL, NULL, "X_QueryWindow", NULL, NULL, e_sssssbbl, NULL, "X_StoreName", d_s, d_string, NULL, NULL, "X_FetchName", NULL, NULL, e_s, e_string, "X_SetIconWindow", d_l, NULL, NULL, NULL, "X_SetResizeHint", d_ssss, NULL, NULL, NULL, "X_GetResizeHint", NULL, NULL, e_ssss, NULL, "X_DefineCursor", d_l, NULL, NULL, NULL, "X_SelectInput", d_l, NULL, NULL, NULL, "X_GrabMouse", d_ll, NULL, e_, NULL, "X_GrabButton", d_ll, NULL, e_, NULL, "X_QueryMouse", NULL, NULL, e_lsss, NULL, "X_InterpretLocator", d_p, NULL, e_lss, NULL, "X_WarpMouse", d_sslssss, NULL, NULL, NULL, "X_FocusKeyboard", NULL, NULL, NULL, NULL, "X_CircWindowDown", NULL, NULL, NULL, NULL, "X_QueryTree", NULL, NULL, e_ll, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "X_Clear", NULL, NULL, NULL, NULL, "X_PixFill", d_ssssul, NULL, NULL, NULL, "X_TileFill", d_ssssll, NULL, NULL, NULL, "X_PixmapPut", d_sssslss, NULL, NULL, NULL, "X_PixmapBitsPut", d_sssssl, d_pixmap, NULL, NULL, "X_BitmapBitsPut", d_ssssuul, d_bitmap, NULL, NULL, "X_CopyArea", d_ssssss, NULL, NULL, NULL, "X_Text", d_ssluusbb, d_string, NULL, NULL, "X_TextMask", d_sslusbb, d_string, NULL, NULL, "X_Line", d_ssssubb, NULL, NULL, NULL, "X_Draw", d_subbsusss, d_vertices, NULL, NULL, "X_DrawFilled", d_sul, d_vertices, NULL, NULL, "X_PixmapSave", d_ssss, NULL, e_l, NULL, "X_PixmapGet", d_ssss, NULL, e_l, e_pixmap, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "", NULL, NULL, NULL, NULL, "X_SetUp", d_lsssu, NULL, e_lsssu, NULL, "X_UngrabMouse", NULL, NULL, NULL, NULL, "X_UngrabButton", NULL, NULL, NULL, NULL, "X_GetColor", d_uuu, NULL, e_u, NULL, "X_GetColorCells", d_ss, NULL, e_u, e_colors, "X_FreeColors", d_s, d_colors, NULL, NULL, "X_StoreColors", d_s, d_colordefs, NULL, NULL, "X_QueryColor", d_u, NULL, e_uuu, NULL, "X_GetFont", d_s, d_string, e_l, NULL, "X_FreeFont", d_l, NULL, NULL, NULL, "X_QueryFont", d_l, NULL, e_ssssss, NULL, /* XXX reply */ "X_CharWidths", d_ls, d_string, e_l, e_shorts, "X_StringWidth", d_ls, d_string, e_s, NULL, "X_FontWidths", d_l, NULL, e_l, e_shorts, "X_StoreBitmap", d_ss, d_bitmap, e_l, NULL, "X_FreeBitmap", d_l, NULL, NULL, NULL, "X_CharBitmap", d_ls, NULL, e_l, NULL, "X_StorePixmap", d_ss, d_pixmap, e_l, NULL, "X_FreePixmap", d_l, NULL, NULL, NULL, "X_MakePixmap", d_luu, NULL, e_l, NULL, "X_QueryShape", d_ss, NULL, e_ss, NULL, "X_StoreCursor", d_luulss, NULL, e_l, NULL, "X_FreeCursor", d_l, NULL, NULL, NULL, "X_MouseControl", d_ss, NULL, NULL, NULL, "X_FeepControl", NULL, NULL, NULL, NULL, "X_Feep", d_s, NULL, NULL, NULL, "X_ShiftLock", NULL, NULL, NULL, NULL, "X_KeyClick", NULL, NULL, NULL, NULL, "X_AutoRepeat", NULL, NULL, NULL, NULL, "X_ScreenSaver", d_ss, NULL, NULL, NULL, "X_StoreBytes", d_s, d_string, NULL, NULL, "X_FetchBytes", NULL, NULL, e_s, e_string, "X_RotateCuts", NULL, NULL, NULL, NULL, "X_AddHost", d_a, NULL, NULL, NULL, "X_RemoveHost", d_a, NULL, NULL, NULL, "X_GetHosts", NULL, NULL, e_l, e_hosts, "X_GrabServer", NULL, NULL, NULL, NULL, "X_UngrabServer", NULL, NULL, NULL, NULL, "X_LookupColor", d_s, d_string, e_uuuuuu, NULL, }; /* * the xreceiveparam primitive takes a string containing the bytes of an XReq * and explodes it, returning the pieces on the stack with the code at * the top. After pushing the pieces, it pushes the number of bytes of * following data. The idea is as follows: * { * xfile xreq readstring * not { exit} if * byteswapconnection { xbyteswap} if * xreceiveparam * dup 0 eq { * string xfile roll readstring * not {exit} if * xreceivedata /xdata roll def * % XXX need to read junk bytes here * } if * xdict begin * cvx exec * end * } loop */ static int x_receiveparam(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop - 1; register unsigned char *xr; register unsigned nb; register struct body *body; register int code; if (optop->type != string_type || optop->value.substring.length != sizeof (XReq)) { ee->error_code = typecheck_error_code; return; } body = body_of(optop); xr = ((unsigned char *) body->body.string.chars) + optop->value.substring.start; ee->optop--; code = *xr; if (code >= ((sizeof XopTable) / (sizeof XopTable[0]))) abort(); if (XopTable[code].Xparam) { (*XopTable[code].Xparam)(ee, (XReq *) xr); nb = BytesOfData((XReq *) xr); } else { nb = 0; } UnpackConstantPart(ee, (XReq *) xr); optop = ee->optop++; set_fixed_object(optop, fracti(nb)); decref(body); } /* * at this point the stack looks like: * string - the right size & full of data * code - the opcode from the Xreq * - the rest of the parameters from the Xreq * afterwards, it will look like: * data - a string or an array or... * code - the opcode */ static int x_receivedata(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop - 2; register char *xr; register int code; if (optop[1].type != string_type || optop->type != fixed_type) { ee->error_code = typecheck_error_code; return; } code = floorfr(optop->value.fixed); if (XopTable[code].Xpdata) { (*XopTable[code].Xpdata)(ee); } } /* * Before the xtransmitparam primitive, the stack looks like: * code - the opcode from the XReq * params - lots of parameters, number depends on code * After, it looks like: * string - the encoded parameters */ static int x_transmitparam(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop - 1; register unsigned char code; struct object xrep; if (optop->type != fixed_type) { ee->error_code = typecheck_error_code; return; } code = floorfr(optop->value.fixed); ee->optop--; xrep = make_string(sizeof (XRep), 0); bzero(body_of(&xrep)->body.string.chars, sizeof (XRep)); ((XRep *) body_of(&xrep)->body.string.chars)->code = code == 0 ? X_Error : X_Reply; if (XopTable[code].Xreply) { (*XopTable[code].Xreply)(ee,(XRep *)body_of(&xrep)->body.string.chars); } xrep.value.substring.start = 0; xrep.value.substring.length = sizeof (XRep); body_of(&xrep)->body.string.used = sizeof (XRep); *(ee->optop) = xrep; ee->optop++; } /* * Before x_transmitdata, the stack should look like * code - the request code * data - a string or an array or whatever, depending upon * the request code * * afterwards, it will look like: * string - the right size & full of data */ static int x_transmitdata(ee) register struct execution_environment *ee; { unsigned char code; if ( ee->optop[-1].type != fixed_type ) { ee->error_code = typecheck_error_code; return; } code = floorfr( ee->optop[-1].value.fixed ); ee->optop--; if (XopTable[code].Xrdata) { (*XopTable[code].Xrdata)(ee); } } /* * The xtransmitevent primitive is similar to xtransmitparam, except that * the code is an event code and the parameters are packed into an XRep * according to this event code. This routine uses a switch statement * instead of a table like XopTable because the event codes are bits in a * word instead of numbers (i.e. 0x0001, 0x0002, 0x0004, ... instead of 1, * 2, 3, ....) and because many of the events take the same parameters. * * Before the xtransmitevent primitive, the stack looks like: * code - the event type (KeyPressed, EnterWindow, etc.) * params - lots of parameters, number depends on event type * After, it looks like: * string - the encoded parameters */ x_transmitevent(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop - 1; struct object xrep; long event_type; XRep* xreply; if ( optop->type != fixed_type ) { ee->error_code = typecheck_error_code; return; } event_type = floorfr( optop->value.fixed ); ee->optop--; xrep = make_string(sizeof(XRep), 0); bzero( body_of(&xrep)->body.string.chars, sizeof(XRep) ); xreply = (XRep *) body_of(&xrep)->body.string.chars; ((XRep *) body_of(&xrep)->body.string.chars)->code = event_type; switch ( event_type ) { case KeyPressed: case KeyReleased: case ButtonPressed: case ButtonReleased: case EnterWindow: case LeaveWindow: case MouseMoved: e_lssssll(ee,(XRep *)body_of(&xrep)->body.string.chars); break; case ExposeWindow: case ExposeRegion: e_lssslss(ee,(XRep *)body_of(&xrep)->body.string.chars); break; case ExposeCopy: case UnmapWindow: e_ll(ee,(XRep *)body_of(&xrep)->body.string.chars); break; case FocusChange: e_lsl(ee,(XRep *)body_of(&xrep)->body.string.chars); break; } xrep.value.substring.start = 0; xrep.value.substring.length = sizeof (XRep); body_of(&xrep)->body.string.used = sizeof (XRep); *(ee->optop) = xrep; ee->optop++; } /* * Byte swaps the string argument */ static int x_byteswap(ee) register struct execution_environment *ee; { register struct object *optop = ee->optop - 1; register short *p; register int n; if (optop->type != string_type) { ee->error_code = typecheck_error_code; return; } p = (short *) (body_of(optop)->body.string.chars + optop->value.substring.start); n = optop->value.substring.length * sizeof (char) / sizeof (short); /* * We should use swab() here, but that would mean alloc-ing * another buffer, etc. */ while (n--) { *p = ((*p & 0377)<<8) | ((*p >> 8) & 0377); p++; } } static UnpackConstantPart(ee, xr) register struct execution_environment *ee; register XReq *xr; { register struct object *optop = ee->optop; set_fixed_object(optop, fracti(xr->windowId)); optop++; set_fixed_object(optop, fracti(xr->mask)); optop++; set_fixed_object(optop, fracti(xr->func)); optop++; set_fixed_object(optop, fracti(xr->code)); ee->optop += 4; return (0); } /* name funct indx args res */ initialize_Xparse () { define_operator("xreceiveparam", x_receiveparam, 0, 1, 14); define_operator("xreceivedata", x_receivedata, 0, 2, 2); define_operator("xtransmitparam", x_transmitparam, 0, 2, 1); define_operator("xtransmitdata", x_transmitdata, 0, 2, 1); define_operator("xtransmitevent", x_transmitevent, 0, 2, 1); define_operator("xbyteswap", x_byteswap, 0, 1, 1); }