From 827843405f67b88e62380846eb96969b389117d5 Mon Sep 17 00:00:00 2001 From: Skip Montanaro Date: Tue, 16 Feb 2021 20:14:40 -0600 Subject: a different extraction of the shell archives --- shar/python-0.9.1-17-21.shar | 2520 +++++++++++++++++++++--------------------- 1 file changed, 1260 insertions(+), 1260 deletions(-) (limited to 'shar/python-0.9.1-17-21.shar') diff --git a/shar/python-0.9.1-17-21.shar b/shar/python-0.9.1-17-21.shar index 1ab184e..7e27790 100644 --- a/shar/python-0.9.1-17-21.shar +++ b/shar/python-0.9.1-17-21.shar @@ -30,153 +30,153 @@ X Xsurfknots = [-1, -1, -1, -1, 1, 1, 1, 1] X Xdef make_ctlpoints(): -X c = [] -X # -X ci = [] -X ci.append(-2.5, -3.7, 1.0) -X ci.append(-1.5, -3.7, 3.0) -X ci.append(1.5, -3.7, -2.5) -X ci.append(2.5, -3.7, -0.75) -X c.append(ci) -X # -X ci = [] -X ci.append(-2.5, -2.0, 3.0) -X ci.append(-1.5, -2.0, 4.0) -X ci.append(1.5, -2.0, -3.0) -X ci.append(2.5, -2.0, 0.0) -X c.append(ci) -X # -X ci = [] -X ci.append(-2.5, 2.0, 1.0) -X ci.append(-1.5, 2.0, 0.0) -X ci.append(1.5, 2.0, -1.0) -X ci.append(2.5, 2.0, 2.0) -X c.append(ci) -X # -X ci = [] -X ci.append(-2.5, 2.7, 1.25) -X ci.append(-1.5, 2.7, 0.1) -X ci.append(1.5, 2.7, -0.6) -X ci.append(2.5, 2.7, 0.2) -X c.append(ci) -X # -X return c +X c = [] +X # +X ci = [] +X ci.append(-2.5, -3.7, 1.0) +X ci.append(-1.5, -3.7, 3.0) +X ci.append(1.5, -3.7, -2.5) +X ci.append(2.5, -3.7, -0.75) +X c.append(ci) +X # +X ci = [] +X ci.append(-2.5, -2.0, 3.0) +X ci.append(-1.5, -2.0, 4.0) +X ci.append(1.5, -2.0, -3.0) +X ci.append(2.5, -2.0, 0.0) +X c.append(ci) +X # +X ci = [] +X ci.append(-2.5, 2.0, 1.0) +X ci.append(-1.5, 2.0, 0.0) +X ci.append(1.5, 2.0, -1.0) +X ci.append(2.5, 2.0, 2.0) +X c.append(ci) +X # +X ci = [] +X ci.append(-2.5, 2.7, 1.25) +X ci.append(-1.5, 2.7, 0.1) +X ci.append(1.5, 2.7, -0.6) +X ci.append(2.5, 2.7, 0.2) +X c.append(ci) +X # +X return c X Xctlpoints = make_ctlpoints() X -Xtrimknots = [0., 0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 4.] +Xtrimknots = [0., 0., 0., 1., 1., 2., 2., 3., 3., 4., 4., 4.] X Xdef make_trimpoints(): -X c = [] -X c.append(1.0, 0.0, 1.0) -X c.append(1.0, 1.0, 1.0) -X c.append(0.0, 2.0, 2.0) -X c.append(-1.0, 1.0, 1.0) -X c.append(-1.0, 0.0, 1.0) -X c.append(-1.0, -1.0, 1.0) -X c.append(0.0, -2.0, 2.0) -X c.append(1.0, -1.0, 1.0) -X c.append(1.0, 0.0, 1.0) -X return c +X c = [] +X c.append(1.0, 0.0, 1.0) +X c.append(1.0, 1.0, 1.0) +X c.append(0.0, 2.0, 2.0) +X c.append(-1.0, 1.0, 1.0) +X c.append(-1.0, 0.0, 1.0) +X c.append(-1.0, -1.0, 1.0) +X c.append(0.0, -2.0, 2.0) +X c.append(1.0, -1.0, 1.0) +X c.append(1.0, 0.0, 1.0) +X return c X Xtrimpoints = make_trimpoints() X Xdef main(): -X init_windows() -X setup_queue() -X make_lights() -X init_view() -X # -X set_scene() -X setnurbsproperty( N_ERRORCHECKING, 1.0 ) -X setnurbsproperty( N_PIXEL_TOLERANCE, 50.0 ) -X trim_flag = 0 -X draw_trim_surface(trim_flag) -X # -X while 1: -X while qtest(): -X dev, val = qread() -X if dev = ESCKEY: -X return -X elif dev = WINQUIT: -X dglclose(-1) # this for DGL only -X return -X elif dev = REDRAW: -X reshapeviewport() -X set_scene() -X draw_trim_surface(trim_flag) -X elif dev = LEFTMOUSE: -X if val: -X trim_flag = (not trim_flag) -X set_scene() -X draw_trim_surface(trim_flag) +X init_windows() +X setup_queue() +X make_lights() +X init_view() +X # +X set_scene() +X setnurbsproperty( N_ERRORCHECKING, 1.0 ) +X setnurbsproperty( N_PIXEL_TOLERANCE, 50.0 ) +X trim_flag = 0 +X draw_trim_surface(trim_flag) +X # +X while 1: +X while qtest(): +X dev, val = qread() +X if dev = ESCKEY: +X return +X elif dev = WINQUIT: +X dglclose(-1) # this for DGL only +X return +X elif dev = REDRAW: +X reshapeviewport() +X set_scene() +X draw_trim_surface(trim_flag) +X elif dev = LEFTMOUSE: +X if val: +X trim_flag = (not trim_flag) +X set_scene() +X draw_trim_surface(trim_flag) X Xdef init_windows(): -X foreground() -X #prefposition(0, 500, 0, 500) -X wid = winopen('nurbs') -X wintitle('NURBS Surface') -X doublebuffer() -X RGBmode() -X gconfig() -X lsetdepth(0x000, 0x7fffff) -X zbuffer( TRUE ) +X foreground() +X #prefposition(0, 500, 0, 500) +X wid = winopen('nurbs') +X wintitle('NURBS Surface') +X doublebuffer() +X RGBmode() +X gconfig() +X lsetdepth(0x000, 0x7fffff) +X zbuffer( TRUE ) X Xdef setup_queue(): -X qdevice(ESCKEY) -X qdevice(REDRAW) -X qdevice(RIGHTMOUSE) -X qdevice(WINQUIT) -X qdevice(LEFTMOUSE) #trimming +X qdevice(ESCKEY) +X qdevice(REDRAW) +X qdevice(RIGHTMOUSE) +X qdevice(WINQUIT) +X qdevice(LEFTMOUSE) #trimming X Xdef init_view(): -X mmode(MPROJECTION) -X ortho( -4., 4., -4., 4., -4., 4. ) -X # -X mmode(MVIEWING) -X loadmatrix(idmat) -X # -X lmbind(MATERIAL, 1) +X mmode(MPROJECTION) +X ortho( -4., 4., -4., 4., -4., 4. ) +X # +X mmode(MVIEWING) +X loadmatrix(idmat) +X # +X lmbind(MATERIAL, 1) X Xdef set_scene(): -X lmbind(MATERIAL, 0) -X RGBcolor(150,150,150) -X lmbind(MATERIAL, 1) -X clear() -X zclear() -X # -X rotate( 100, 'y' ) -X rotate( 100, 'z' ) +X lmbind(MATERIAL, 0) +X RGBcolor(150,150,150) +X lmbind(MATERIAL, 1) +X clear() +X zclear() +X # +X rotate( 100, 'y' ) +X rotate( 100, 'z' ) X Xdef draw_trim_surface(trim_flag): -X bgnsurface() -X nurbssurface(surfknots, surfknots, ctlpoints, ORDER, ORDER, N_XYZ) -X if trim_flag: -X bgntrim() -X nurbscurve(trimknots, trimpoints, ORDER-1, N_STW) -X endtrim() -X endsurface() -X swapbuffers() +X bgnsurface() +X nurbssurface(surfknots, surfknots, ctlpoints, ORDER, ORDER, N_XYZ) +X if trim_flag: +X bgntrim() +X nurbscurve(trimknots, trimpoints, ORDER-1, N_STW) +X endtrim() +X endsurface() +X swapbuffers() X Xdef make_lights(): -X lmdef(DEFLMODEL,1,[]) -X lmdef(DEFLIGHT,1,[]) -X # -X # define material #1 -X # -X a = [] -X a = a + [EMISSION, 0.0, 0.0, 0.0] -X a = a + [AMBIENT, 0.1, 0.1, 0.1] -X a = a + [DIFFUSE, 0.6, 0.3, 0.3] -X a = a + [SPECULAR, 0.0, 0.6, 0.0] -X a = a + [SHININESS, 2.0] -X a = a + [LMNULL] -X lmdef(DEFMATERIAL, 1, a) -X # -X # turn on lighting -X # -X lmbind(LIGHT0, 1) -X lmbind(LMODEL, 1) +X lmdef(DEFLMODEL,1,[]) +X lmdef(DEFLIGHT,1,[]) +X # +X # define material #1 +X # +X a = [] +X a = a + [EMISSION, 0.0, 0.0, 0.0] +X a = a + [AMBIENT, 0.1, 0.1, 0.1] +X a = a + [DIFFUSE, 0.6, 0.3, 0.3] +X a = a + [SPECULAR, 0.0, 0.6, 0.0] +X a = a + [SHININESS, 2.0] +X a = a + [LMNULL] +X lmdef(DEFMATERIAL, 1, a) +X # +X # turn on lighting +X # +X lmbind(LIGHT0, 1) +X lmbind(LMODEL, 1) X Xmain() EOF @@ -189,14 +189,14 @@ echo 'x - demo/sgi/gl/zrgb.py' sed 's/^X//' > 'demo/sgi/gl/zrgb.py' << 'EOF' X#! /ufs/guido/bin/sgi/python X -X# zrgb (Requires Z buffer.) +X# zrgb (Requires Z buffer.) X# X# This program demostrates zbuffering 3 intersecting RGB polygons while -X# in doublebuffer mode where, movement of the mouse with the LEFTMOUSE +X# in doublebuffer mode where, movement of the mouse with the LEFTMOUSE X# button depressed will, rotate the 3 polygons. This is done by compound -X# rotations allowing continuous screen-oriented rotations. +X# rotations allowing continuous screen-oriented rotations. X# -X# Press the "Esc" key to exit. +X# Press the "Esc" key to exit. X Xfrom gl import * Xfrom GL import * @@ -208,115 +208,115 @@ X Xidmat=[1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0,0.0,0.0,0.0,0.0,1.0] X Xdef main() : -X # -X # old and new mouse position -X # -X # -X mode = 0 -X omx = 0 -X mx = 0 -X omy = 0 -X my = 0 -X # -X initialize () -X # -X draw_scene (objmat) -X # -X while (1) : -X # -X dev, val = qread() -X # -X if dev = ESCKEY : -X if val : -X break -X # exit when key is going up, not down -X # this avoids the scenario where a window -X # underneath this program's window -X # would otherwise "eat up" the up- -X # event of the Esc key being released -X return -X # -X elif dev = REDRAW : -X reshapeviewport() -X draw_scene(objmat) -X # -X elif dev = LEFTMOUSE: -X omx = mx -X omy = my -X if val : -X mode = 1 -X else : -X mode = 0 -X elif dev = MOUSEX : -X omx = mx -X mx = val -X #print omx, mx -X objmat = update_scene(objmat,mx,my,omx,omy,mode) -X # -X elif dev = MOUSEY : -X omy = my -X my = val -X #print omy, my -X objmat = update_scene(objmat,mx,my,omx,omy,mode) -X # +X # +X # old and new mouse position +X # +X # +X mode = 0 +X omx = 0 +X mx = 0 +X omy = 0 +X my = 0 +X # +X initialize () +X # +X draw_scene (objmat) +X # +X while (1) : +X # +X dev, val = qread() +X # +X if dev = ESCKEY : +X if val : +X break +X # exit when key is going up, not down +X # this avoids the scenario where a window +X # underneath this program's window +X # would otherwise "eat up" the up- +X # event of the Esc key being released +X return +X # +X elif dev = REDRAW : +X reshapeviewport() +X draw_scene(objmat) +X # +X elif dev = LEFTMOUSE: +X omx = mx +X omy = my +X if val : +X mode = 1 +X else : +X mode = 0 +X elif dev = MOUSEX : +X omx = mx +X mx = val +X #print omx, mx +X objmat = update_scene(objmat,mx,my,omx,omy,mode) +X # +X elif dev = MOUSEY : +X omy = my +X my = val +X #print omy, my +X objmat = update_scene(objmat,mx,my,omx,omy,mode) +X # X X Xdef initialize () : -X # -X foreground () -X keepaspect(5, 4) -X w = winopen('Zbuffered RGB') -X # -X doublebuffer() -X RGBmode() -X gconfig() -X zbuffer(1) -X lsetdepth(0x0, 0x7FFFFF) -X # -X qdevice(ESCKEY) -X qdevice(LEFTMOUSE) -X qdevice(MOUSEX) -X qdevice(MOUSEY) +X # +X foreground () +X keepaspect(5, 4) +X w = winopen('Zbuffered RGB') +X # +X doublebuffer() +X RGBmode() +X gconfig() +X zbuffer(1) +X lsetdepth(0x0, 0x7FFFFF) +X # +X qdevice(ESCKEY) +X qdevice(LEFTMOUSE) +X qdevice(MOUSEX) +X qdevice(MOUSEY) X Xdef update_scene (mat, mx, my, omx, omy, mode) : -X # -X if mode = 1 : -X mat = orient(mat, mx, my, omx, omy) -X draw_scene(mat) -X return mat +X # +X if mode = 1 : +X mat = orient(mat, mx, my, omx, omy) +X draw_scene(mat) +X return mat X Xdef orient (mat, mx, my, omx, omy) : -X # -X # -X pushmatrix() -X loadmatrix(idmat) -X # -X if mx - omx : rot (float (mx - omx), 'y') -X if omy - my : rot (float (omy - my), 'x') -X # -X multmatrix(mat) -X mat = getmatrix() -X # -X # -X popmatrix() -X # -X return mat +X # +X # +X pushmatrix() +X loadmatrix(idmat) +X # +X if mx - omx : rot (float (mx - omx), 'y') +X if omy - my : rot (float (omy - my), 'x') +X # +X multmatrix(mat) +X mat = getmatrix() +X # +X # +X popmatrix() +X # +X return mat X Xdef draw_scene (mat) : -X RGBcolor(40, 100, 200) -X clear() -X zclear() -X # -X perspective(400, 1.25, 30.0, 60.0) -X translate(0.0, 0.0, -40.0) -X multmatrix(mat) -X # -X # skews original view to show all polygons -X # -X rotate(-580, 'y') -X draw_polys() -X # -X swapbuffers() +X RGBcolor(40, 100, 200) +X clear() +X zclear() +X # +X perspective(400, 1.25, 30.0, 60.0) +X translate(0.0, 0.0, -40.0) +X multmatrix(mat) +X # +X # skews original view to show all polygons +X # +X rotate(-580, 'y') +X draw_polys() +X # +X swapbuffers() X Xpolygon1 = [(-10.0,-10.0,0.0),(10.0,-10.0,0.0),(-10.0,10.0,0.0)] X @@ -325,34 +325,34 @@ X Xpolygon3 = [(-10.0,6.0,4.0),(-10.0,3.0,4.0),(4.0,-9.0,-10.0),(4.0,-6.0,-10.0)] X Xdef draw_polys(): -X bgnpolygon() -X cpack(0x0) -X v3f(polygon1[0]) -X cpack(0x007F7F7F) -X v3f(polygon1[1]) -X cpack(0x00FFFFFF) -X v3f(polygon1[2]) -X endpolygon() -X # -X bgnpolygon() -X cpack(0x0000FFFF) -X v3f(polygon2[0]) -X cpack(0x007FFF00) -X v3f(polygon2[1]) -X cpack(0x00FF0000) -X v3f(polygon2[2]) -X endpolygon() -X # -X bgnpolygon() -X cpack(0x0000FFFF) -X v3f(polygon3[0]) -X cpack(0x00FF00FF) -X v3f(polygon3[1]) -X cpack(0x00FF0000) -X v3f(polygon3[2]) -X cpack(0x00FF00FF) -X v3f(polygon3[3]) -X endpolygon() +X bgnpolygon() +X cpack(0x0) +X v3f(polygon1[0]) +X cpack(0x007F7F7F) +X v3f(polygon1[1]) +X cpack(0x00FFFFFF) +X v3f(polygon1[2]) +X endpolygon() +X # +X bgnpolygon() +X cpack(0x0000FFFF) +X v3f(polygon2[0]) +X cpack(0x007FFF00) +X v3f(polygon2[1]) +X cpack(0x00FF0000) +X v3f(polygon2[2]) +X endpolygon() +X # +X bgnpolygon() +X cpack(0x0000FFFF) +X v3f(polygon3[0]) +X cpack(0x00FF00FF) +X v3f(polygon3[1]) +X cpack(0x00FF0000) +X v3f(polygon3[2]) +X cpack(0x00FF00FF) +X v3f(polygon3[3]) +X endpolygon() X X Xmain () @@ -520,143 +520,143 @@ X X# first try - brute force method (ala M.Overmars...) X Xdef makespinobject (smooth,rot,n,x1,z1,nx1,nz1,x2,z2,nx2,nz2) : -X object = [] -X dth = 2.0 * pi / float (rot) -X for i in range (0, n) : -X for j in range (0, rot) : -X th = dth * float (j) -X # -X if smooth = 1: -X a1 = th -X a2 =th+dth -X else : -X a1 = th + dth / 2.0 -X a2 = th + dth / 2.0 -X # -X v0 = (x1[i]*sin(th),x1[i]*cos(th),z1[i]) -X n0 = (nx1[i]*sin(a1),nx1[i]*cos(a1),nz1[i]) -X # -X v1 = (x1[i]*sin(th+dth),x1[i]*cos(th+dth),z1[i]) -X n1 = (nx1[i]*sin(a2), nx1[i]*cos(a2), nz1[i]) -X # -X v2 = (x2[i]*sin(th+dth),x2[i]*cos(th+dth),z2[i]) -X n2 = (nx2[i]*sin(a2), nx2[i]*cos(a2), nz2[i]) -X # -X v3 = (x2[i]*sin(th), x2[i]*cos(th), z2[i]) -X n3 = (nx2[i]*sin(a1), nx2[i]*cos(a1), nz2[i]) -X # -X patch = ((v0,n0), (v1,n1), (v2,n2), (v3,n3)) -X #patch = ((n0,v0), (n1,v1), (n2,v2), (n3,v3)) -X # -X if x1[i] < FUZZY : -X patch = patch[1:] -X # -X object.append (patch) -X # -X return object +X object = [] +X dth = 2.0 * pi / float (rot) +X for i in range (0, n) : +X for j in range (0, rot) : +X th = dth * float (j) +X # +X if smooth = 1: +X a1 = th +X a2 =th+dth +X else : +X a1 = th + dth / 2.0 +X a2 = th + dth / 2.0 +X # +X v0 = (x1[i]*sin(th),x1[i]*cos(th),z1[i]) +X n0 = (nx1[i]*sin(a1),nx1[i]*cos(a1),nz1[i]) +X # +X v1 = (x1[i]*sin(th+dth),x1[i]*cos(th+dth),z1[i]) +X n1 = (nx1[i]*sin(a2), nx1[i]*cos(a2), nz1[i]) +X # +X v2 = (x2[i]*sin(th+dth),x2[i]*cos(th+dth),z2[i]) +X n2 = (nx2[i]*sin(a2), nx2[i]*cos(a2), nz2[i]) +X # +X v3 = (x2[i]*sin(th), x2[i]*cos(th), z2[i]) +X n3 = (nx2[i]*sin(a1), nx2[i]*cos(a1), nz2[i]) +X # +X patch = ((v0,n0), (v1,n1), (v2,n2), (v3,n3)) +X #patch = ((n0,v0), (n1,v1), (n2,v2), (n3,v3)) +X # +X if x1[i] < FUZZY : +X patch = patch[1:] +X # +X object.append (patch) +X # +X return object X Xdef makesphere (n): -X asin = [] -X acos = [] -X for i in range (0, n-1): -X asin.append (sin((pi/float (n))*(1.0+float (i)))) -X acos.append(cos((pi/float (n))*(1.0+float (i)))) -X # -X x1 = [0.0] + asin -X z1 = [1.0] + acos -X nx1 = [0.0] + asin -X nz1 = [1.0] + acos -X # -X x2 = asin + [0.0] -X z2 = acos + [-1.0] -X nx2 = asin + [0.0] -X nz2 = acos + [-1.0] -X # -X return makespinobject (1,2*n,n,x1,z1,nx1,nz1,x2,z2,nx2,nz2) +X asin = [] +X acos = [] +X for i in range (0, n-1): +X asin.append (sin((pi/float (n))*(1.0+float (i)))) +X acos.append(cos((pi/float (n))*(1.0+float (i)))) +X # +X x1 = [0.0] + asin +X z1 = [1.0] + acos +X nx1 = [0.0] + asin +X nz1 = [1.0] + acos +X # +X x2 = asin + [0.0] +X z2 = acos + [-1.0] +X nx2 = asin + [0.0] +X nz2 = acos + [-1.0] +X # +X return makespinobject (1,2*n,n,x1,z1,nx1,nz1,x2,z2,nx2,nz2) X Xdef makecylinder(n) : -X x1 = [0.0, 1.0, 1.0] -X nx1 = [0.0, 1.0, 0.0] -X z1 = [1.0, 1.0, -1.0] -X nz1 = [1.0, 0.0, -1.0] -X # -X z2 = [1.0, -1.0, -1.0] -X nz2 = [1.0, 0.0, -1.0] -X x2 = [1.0, 1.0, 0.0] -X nx2 = [0.0, 1.0, 0.0] -X # -X return makespinobject(1,2*n,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) +X x1 = [0.0, 1.0, 1.0] +X nx1 = [0.0, 1.0, 0.0] +X z1 = [1.0, 1.0, -1.0] +X nz1 = [1.0, 0.0, -1.0] +X # +X z2 = [1.0, -1.0, -1.0] +X nz2 = [1.0, 0.0, -1.0] +X x2 = [1.0, 1.0, 0.0] +X nx2 = [0.0, 1.0, 0.0] +X # +X return makespinobject(1,2*n,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) X Xdef makecone(n) : -X x1 = [0.0, 1.0, 1.0] -X nx1 = [2.0/sqrt(5.0), 0.0, 0.0] -X z1 = [1.0, -1.0, -1.0] -X nz1 = [1.0/sqrt(5.0), -1.0, -1.0] -X # -X x2 = [1.0, 0.0, 0.0] -X nx2 = [2.0/sqrt(5.0), 0.0, 0.0] -X nz2 = [1.0/sqrt(5.0), -1.0, -1.0] -X z2 = [-1.0, -1.0, -1.0] -X # -X return makespinobject(1,2*n,2,x1,z1,nx1,nz1,x2,z2,nx2,nz2) +X x1 = [0.0, 1.0, 1.0] +X nx1 = [2.0/sqrt(5.0), 0.0, 0.0] +X z1 = [1.0, -1.0, -1.0] +X nz1 = [1.0/sqrt(5.0), -1.0, -1.0] +X # +X x2 = [1.0, 0.0, 0.0] +X nx2 = [2.0/sqrt(5.0), 0.0, 0.0] +X nz2 = [1.0/sqrt(5.0), -1.0, -1.0] +X z2 = [-1.0, -1.0, -1.0] +X # +X return makespinobject(1,2*n,2,x1,z1,nx1,nz1,x2,z2,nx2,nz2) X Xdef makecube() : -X x1 = [0.0, sqrt(2.0), sqrt (2.0)] -X nx1 = [0.0, 1.0, 0.0] -X z1 = [1.0, 1.0, -1.0] -X nz1 = [1.0, 0.0, -1.0] -X # -X x2 = [sqrt(2.0), sqrt(2.0), 0.0] -X nx2 = [0.0, 1.0, 0.0] -X z2 = [1.0, -1.0, -1.0] -X nz2 = [1.0, 0.0, -1.0] -X # -X return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) +X x1 = [0.0, sqrt(2.0), sqrt (2.0)] +X nx1 = [0.0, 1.0, 0.0] +X z1 = [1.0, 1.0, -1.0] +X nz1 = [1.0, 0.0, -1.0] +X # +X x2 = [sqrt(2.0), sqrt(2.0), 0.0] +X nx2 = [0.0, 1.0, 0.0] +X z2 = [1.0, -1.0, -1.0] +X nz2 = [1.0, 0.0, -1.0] +X # +X return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) X X Xdef makepyramid() : -X x1 = [0.0, sqrt(2.0), 0.0] -X nx1 = [2.0 / sqrt(5.0), 0.0, 0.0] -X z1 = [1.0, -1.0, 0.0] -X nz1 = [1.0 / sqrt(5.0), -1.0, 0.0] -X # -X x2 = [sqrt(2.0), 0.0, 0.0] -X nx2 = [2.0 / sqrt(5.0), 0.0, 0.0] -X z2 = [-1.0, -1.0, -1.0] -X nz2 = [1.0/sqrt(5.0), -1.0, 0.0] -X # -X return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) +X x1 = [0.0, sqrt(2.0), 0.0] +X nx1 = [2.0 / sqrt(5.0), 0.0, 0.0] +X z1 = [1.0, -1.0, 0.0] +X nz1 = [1.0 / sqrt(5.0), -1.0, 0.0] +X # +X x2 = [sqrt(2.0), 0.0, 0.0] +X nx2 = [2.0 / sqrt(5.0), 0.0, 0.0] +X z2 = [-1.0, -1.0, -1.0] +X nz2 = [1.0/sqrt(5.0), -1.0, 0.0] +X # +X return makespinobject(0,4,3,x1,z1,nx1,nz1,x2,z2,nx2,nz2) X Xdef makeobjects () : -X cube = makecube() -X sphere = makesphere (6) -X cylinder = makecylinder (6) -X cone = makecone (6) -X pyramid = makepyramid () -X # -X odict = {} -X odict ['cube'] = cube -X odict ['pyramid'] = pyramid -X odict ['sphere'] = sphere -X odict ['cylinder'] = cylinder -X odict ['cone'] = cone -X odict ['diamond'] = cube -X odict ['disk'] = sphere -X # -X return odict +X cube = makecube() +X sphere = makesphere (6) +X cylinder = makecylinder (6) +X cone = makecone (6) +X pyramid = makepyramid () +X # +X odict = {} +X odict ['cube'] = cube +X odict ['pyramid'] = pyramid +X odict ['sphere'] = sphere +X odict ['cylinder'] = cylinder +X odict ['cone'] = cone +X odict ['diamond'] = cube +X odict ['disk'] = sphere +X # +X return odict X X Xrenderfuncs = [bgnpolygon, endpolygon] X Xdef putFunc (funcs) : -X renderfuncs [:] = funcs +X renderfuncs [:] = funcs X Xdef drawobject (obj) : -X # -X for patch in obj : -X renderfuncs[0] () -X vnarray (patch) -X renderfuncs[1] () +X # +X for patch in obj : +X renderfuncs[0] () +X vnarray (patch) +X renderfuncs[1] () X EOF fi @@ -670,117 +670,117 @@ X# Use as a base class for other splits. X# Derived classes should at least implement the methods that call X# unimpl() below: minsize(), getbounds() and setbounds(). X -XError = 'Split.Error' # Exception +XError = 'Split.Error' # Exception X Ximport rect Xfrom util import remove X Xclass Split(): -X # -X # Calls from creator -X # NB derived classes may add parameters to create() -X # -X def create(self, parent): -X parent.addchild(self) -X self.parent = parent -X self.children = [] -X self.mouse_interest = [] -X self.timer_interest = [] -X self.mouse_focus = 0 -X return self -X # -X # Downcalls from parent to child -X # -X def destroy(self): -X self.parent = None -X for child in self.children: -X child.destroy() -X del self.children[:] -X del self.mouse_interest[:] -X del self.timer_interest[:] -X self.mouse_focus = None -X # -X def minsize(self, m): return unimpl() -X def getbounds(self): return unimpl() -X def setbounds(self, bounds): unimpl() -X # -X def draw(self, d_detail): -X # (Could avoid calls to children outside the area) -X for child in self.children: -X child.draw(d_detail) -X # -X # Downcalls only made after certain upcalls -X # -X def mouse_down(self, detail): -X if self.mouse_focus: -X self.mouse_focus.mouse_down(detail) -X p = detail[0] -X for child in self.mouse_interest: -X if rect.pointinrect(p, child.getbounds()): -X self.mouse_focus = child -X child.mouse_down(detail) -X def mouse_move(self, detail): -X if self.mouse_focus: -X self.mouse_focus.mouse_move(detail) -X def mouse_up(self, detail): -X if self.mouse_focus: -X self.mouse_focus.mouse_up(detail) -X self.mouse_focus = 0 -X # -X def timer(self): -X for child in self.timer_interest: -X child.timer() -X # -X # Upcalls from child to parent -X # -X def addchild(self, child): -X if child in self.children: -X raise Error, 'addchild: child already inlist' -X self.children.append(child) -X def delchild(self, child): -X if child not in self.children: -X raise Error, 'delchild: child not in list' -X remove(child, self.children) -X if child in self.mouse_interest: -X remove(child, self.mouse_interest) -X if child in self.timer_interest: -X remove(child, self.timer_interest) -X if child = self.mouse_focus: -X self.mouse_focus = 0 -X # -X def need_mouse(self, child): -X if child not in self.mouse_interest: -X self.mouse_interest.append(child) -X self.parent.need_mouse(self) -X def no_mouse(self, child): -X if child in self.mouse_interest: -X remove(child, self.mouse_interest) -X if not self.mouse_interest: -X self.parent.no_mouse(self) -X # -X def need_timer(self, child): -X if child not in self.timer_interest: -X self.timer_interest.append(child) -X self.parent.need_timer(self) -X def no_timer(self, child): -X if child in self.timer_interest: -X remove(child, self.timer_interest) -X if not self.timer_interest: -X self.parent.no_timer(self) -X # -X # The rest are transparent: -X # -X def begindrawing(self): -X return self.parent.begindrawing() -X def beginmeasuring(self): -X return self.parent.beginmeasuring() -X # -X def change(self, area): -X self.parent.change(area) -X def scroll(self, area_vector): -X self.parent.scroll(area_vector) -X def settimer(self, itimer): -X self.parent.settimer(itimer) +X # +X # Calls from creator +X # NB derived classes may add parameters to create() +X # +X def create(self, parent): +X parent.addchild(self) +X self.parent = parent +X self.children = [] +X self.mouse_interest = [] +X self.timer_interest = [] +X self.mouse_focus = 0 +X return self +X # +X # Downcalls from parent to child +X # +X def destroy(self): +X self.parent = None +X for child in self.children: +X child.destroy() +X del self.children[:] +X del self.mouse_interest[:] +X del self.timer_interest[:] +X self.mouse_focus = None +X # +X def minsize(self, m): return unimpl() +X def getbounds(self): return unimpl() +X def setbounds(self, bounds): unimpl() +X # +X def draw(self, d_detail): +X # (Could avoid calls to children outside the area) +X for child in self.children: +X child.draw(d_detail) +X # +X # Downcalls only made after certain upcalls +X # +X def mouse_down(self, detail): +X if self.mouse_focus: +X self.mouse_focus.mouse_down(detail) +X p = detail[0] +X for child in self.mouse_interest: +X if rect.pointinrect(p, child.getbounds()): +X self.mouse_focus = child +X child.mouse_down(detail) +X def mouse_move(self, detail): +X if self.mouse_focus: +X self.mouse_focus.mouse_move(detail) +X def mouse_up(self, detail): +X if self.mouse_focus: +X self.mouse_focus.mouse_up(detail) +X self.mouse_focus = 0 +X # +X def timer(self): +X for child in self.timer_interest: +X child.timer() +X # +X # Upcalls from child to parent +X # +X def addchild(self, child): +X if child in self.children: +X raise Error, 'addchild: child already inlist' +X self.children.append(child) +X def delchild(self, child): +X if child not in self.children: +X raise Error, 'delchild: child not in list' +X remove(child, self.children) +X if child in self.mouse_interest: +X remove(child, self.mouse_interest) +X if child in self.timer_interest: +X remove(child, self.timer_interest) +X if child = self.mouse_focus: +X self.mouse_focus = 0 +X # +X def need_mouse(self, child): +X if child not in self.mouse_interest: +X self.mouse_interest.append(child) +X self.parent.need_mouse(self) +X def no_mouse(self, child): +X if child in self.mouse_interest: +X remove(child, self.mouse_interest) +X if not self.mouse_interest: +X self.parent.no_mouse(self) +X # +X def need_timer(self, child): +X if child not in self.timer_interest: +X self.timer_interest.append(child) +X self.parent.need_timer(self) +X def no_timer(self, child): +X if child in self.timer_interest: +X remove(child, self.timer_interest) +X if not self.timer_interest: +X self.parent.no_timer(self) +X # +X # The rest are transparent: +X # +X def begindrawing(self): +X return self.parent.begindrawing() +X def beginmeasuring(self): +X return self.parent.beginmeasuring() +X # +X def change(self, area): +X self.parent.change(area) +X def scroll(self, area_vector): +X self.parent.scroll(area_vector) +X def settimer(self, itimer): +X self.parent.settimer(itimer) EOF fi if test -s 'lib/WindowParent.py' @@ -797,98 +797,98 @@ Xfrom stdwinevents import * X Xfrom TransParent import ManageOneChild X -XError = 'WindowParent.Error' # Exception +XError = 'WindowParent.Error' # Exception X Xclass WindowParent() = ManageOneChild(): -X # -X def create(self, (title, size)): -X self.title = title -X self.size = size # (width, height) -X self._reset() -X return self -X # -X def _reset(self): -X self.child = 0 -X self.win = 0 -X self.itimer = 0 -X self.do_mouse = 0 -X self.do_timer = 0 -X # -X def destroy(self): -X if self.child: self.child.destroy() -X self._reset() -X # -X def need_mouse(self, child): self.do_mouse = 1 -X def no_mouse(self, child): self.do_mouse = 0 -X # -X def need_timer(self, child): self.do_timer = 1 -X def no_timer(self, child): self.do_timer = 0 -X # -X def realize(self): -X if self.win: -X raise Error, 'realize(): called twice' -X if not self.child: -X raise Error, 'realize(): no child' -X size = self.child.minsize(self.beginmeasuring()) -X self.size = max(self.size[0], size[0]), \ -X max(self.size[1], size[1]) -X #stdwin.setdefwinsize(self.size) -X # XXX Compensate stdwin bug: -X stdwin.setdefwinsize(self.size[0]+4, self.size[1]+2) -X self.win = stdwin.open(self.title) -X if self.itimer: -X self.win.settimer(self.itimer) -X bounds = (0, 0), self.win.getwinsize() -X self.child.setbounds(bounds) -X # -X def beginmeasuring(self): -X # Return something with which a child can measure text -X if self.win: -X return self.win.begindrawing() -X else: -X return stdwin -X # -X def begindrawing(self): -X if self.win: -X return self.win.begindrawing() -X else: -X raise Error, 'begindrawing(): not realized yet' -X # -X def change(self, area): -X if self.win: -X self.win.change(area) -X # -X def scroll(self, args): -X if self.win: -X self.win.scroll(args) -X # -X def settimer(self, itimer): -X if self.win: -X self.win.settimer(itimer) -X else: -X self.itimer = itimer -X # -X # Only call dispatch if we have a child -X # -X def dispatch(self, (type, win, detail)): -X if win <> self.win: -X return -X elif type = WE_DRAW: -X d = self.win.begindrawing() -X self.child.draw(d, detail) -X elif type = WE_MOUSE_DOWN: -X if self.do_mouse: self.child.mouse_down(detail) -X elif type = WE_MOUSE_MOVE: -X if self.do_mouse: self.child.mouse_move(detail) -X elif type = WE_MOUSE_UP: -X if self.do_mouse: self.child.mouse_up(detail) -X elif type = WE_TIMER: -X if self.do_timer: self.child.timer() -X elif type = WE_SIZE: -X self.win.change((0, 0), (10000, 10000)) # XXX -X bounds = (0, 0), self.win.getwinsize() -X self.child.setbounds(bounds) -X # +X # +X def create(self, (title, size)): +X self.title = title +X self.size = size # (width, height) +X self._reset() +X return self +X # +X def _reset(self): +X self.child = 0 +X self.win = 0 +X self.itimer = 0 +X self.do_mouse = 0 +X self.do_timer = 0 +X # +X def destroy(self): +X if self.child: self.child.destroy() +X self._reset() +X # +X def need_mouse(self, child): self.do_mouse = 1 +X def no_mouse(self, child): self.do_mouse = 0 +X # +X def need_timer(self, child): self.do_timer = 1 +X def no_timer(self, child): self.do_timer = 0 +X # +X def realize(self): +X if self.win: +X raise Error, 'realize(): called twice' +X if not self.child: +X raise Error, 'realize(): no child' +X size = self.child.minsize(self.beginmeasuring()) +X self.size = max(self.size[0], size[0]), \ +X max(self.size[1], size[1]) +X #stdwin.setdefwinsize(self.size) +X # XXX Compensate stdwin bug: +X stdwin.setdefwinsize(self.size[0]+4, self.size[1]+2) +X self.win = stdwin.open(self.title) +X if self.itimer: +X self.win.settimer(self.itimer) +X bounds = (0, 0), self.win.getwinsize() +X self.child.setbounds(bounds) +X # +X def beginmeasuring(self): +X # Return something with which a child can measure text +X if self.win: +X return self.win.begindrawing() +X else: +X return stdwin +X # +X def begindrawing(self): +X if self.win: +X return self.win.begindrawing() +X else: +X raise Error, 'begindrawing(): not realized yet' +X # +X def change(self, area): +X if self.win: +X self.win.change(area) +X # +X def scroll(self, args): +X if self.win: +X self.win.scroll(args) +X # +X def settimer(self, itimer): +X if self.win: +X self.win.settimer(itimer) +X else: +X self.itimer = itimer +X # +X # Only call dispatch if we have a child +X # +X def dispatch(self, (type, win, detail)): +X if win <> self.win: +X return +X elif type = WE_DRAW: +X d = self.win.begindrawing() +X self.child.draw(d, detail) +X elif type = WE_MOUSE_DOWN: +X if self.do_mouse: self.child.mouse_down(detail) +X elif type = WE_MOUSE_MOVE: +X if self.do_mouse: self.child.mouse_move(detail) +X elif type = WE_MOUSE_UP: +X if self.do_mouse: self.child.mouse_up(detail) +X elif type = WE_TIMER: +X if self.do_timer: self.child.timer() +X elif type = WE_SIZE: +X self.win.change((0, 0), (10000, 10000)) # XXX +X bounds = (0, 0), self.win.getwinsize() +X self.child.setbounds(bounds) +X # EOF fi if test -s 'lib/gwin.py' @@ -907,113 +907,113 @@ Xfrom stdwinevents import * X X# XXX Old version of stdwinevents, should go Ximport stdwinsupport -XS = stdwinsupport # Shorthand +XS = stdwinsupport # Shorthand X -Xwindows = [] # List of open windows +Xwindows = [] # List of open windows X X X# Open a window X -Xdef open(title): # Open a generic window -X w = stdwin.open(title) -X stdwin.setdefwinsize(0, 0) -X # Set default event handlers -X w.draw = nop -X w.char = nop -X w.mdown = nop -X w.mmove = nop -X w.mup = nop -X w.m2down = m2down -X w.m2up = m2up -X w.size = nop -X w.move = nop -X w.activate = w.deactivate = nop -X w.timer = nop -X # default command handlers -X w.close = close -X w.tab = tab -X w.enter = enter -X w.backspace = backspace -X w.arrow = arrow -X w.kleft = w.kup = w.kright = w.kdown = nop -X windows.append(w) -X return w +Xdef open(title): # Open a generic window +X w = stdwin.open(title) +X stdwin.setdefwinsize(0, 0) +X # Set default event handlers +X w.draw = nop +X w.char = nop +X w.mdown = nop +X w.mmove = nop +X w.mup = nop +X w.m2down = m2down +X w.m2up = m2up +X w.size = nop +X w.move = nop +X w.activate = w.deactivate = nop +X w.timer = nop +X # default command handlers +X w.close = close +X w.tab = tab +X w.enter = enter +X w.backspace = backspace +X w.arrow = arrow +X w.kleft = w.kup = w.kright = w.kdown = nop +X windows.append(w) +X return w X X X# Generic event dispatching X -Xdef mainloop(): # Handle events until no windows left -X while windows: -X treatevent(stdwin.getevent()) -X -Xdef treatevent(e): # Handle a stdwin event -X type, w, detail = e -X if type = S.we_draw: -X w.draw(w, detail) -X elif type = S.we_menu: -X m, item = detail -X m.action[item](w, m, item) -X elif type = S.we_command: -X treatcommand(w, detail) -X elif type = S.we_char: -X w.char(w, detail) -X elif type = S.we_mouse_down: -X if detail[1] > 1: w.m2down(w, detail) -X else: w.mdown(w, detail) -X elif type = S.we_mouse_move: -X w.mmove(w, detail) -X elif type = S.we_mouse_up: -X if detail[1] > 1: w.m2up(w, detail) -X else: w.mup(w, detail) -X elif type = S.we_size: -X w.size(w, w.getwinsize()) -X elif type = S.we_activate: -X w.activate(w) -X elif type = S.we_deactivate: -X w.deactivate(w) -X elif type = S.we_move: -X w.move(w) -X elif type = S.we_timer: -X w.timer(w) -X elif type = WE_CLOSE: -X w.close(w) -X -Xdef treatcommand(w, type): # Handle a we_command event -X if type = S.wc_close: -X w.close(w) -X elif type = S.wc_return: -X w.enter(w) -X elif type = S.wc_tab: -X w.tab(w) -X elif type = S.wc_backspace: -X w.backspace(w) -X elif type in (S.wc_left, S.wc_up, S.wc_right, S.wc_down): -X w.arrow(w, type) +Xdef mainloop(): # Handle events until no windows left +X while windows: +X treatevent(stdwin.getevent()) +X +Xdef treatevent(e): # Handle a stdwin event +X type, w, detail = e +X if type = S.we_draw: +X w.draw(w, detail) +X elif type = S.we_menu: +X m, item = detail +X m.action[item](w, m, item) +X elif type = S.we_command: +X treatcommand(w, detail) +X elif type = S.we_char: +X w.char(w, detail) +X elif type = S.we_mouse_down: +X if detail[1] > 1: w.m2down(w, detail) +X else: w.mdown(w, detail) +X elif type = S.we_mouse_move: +X w.mmove(w, detail) +X elif type = S.we_mouse_up: +X if detail[1] > 1: w.m2up(w, detail) +X else: w.mup(w, detail) +X elif type = S.we_size: +X w.size(w, w.getwinsize()) +X elif type = S.we_activate: +X w.activate(w) +X elif type = S.we_deactivate: +X w.deactivate(w) +X elif type = S.we_move: +X w.move(w) +X elif type = S.we_timer: +X w.timer(w) +X elif type = WE_CLOSE: +X w.close(w) +X +Xdef treatcommand(w, type): # Handle a we_command event +X if type = S.wc_close: +X w.close(w) +X elif type = S.wc_return: +X w.enter(w) +X elif type = S.wc_tab: +X w.tab(w) +X elif type = S.wc_backspace: +X w.backspace(w) +X elif type in (S.wc_left, S.wc_up, S.wc_right, S.wc_down): +X w.arrow(w, type) X X X# Methods X -Xdef close(w): # Close method -X for i in range(len(windows)): -X if windows[i] is w: -X del windows[i] -X break +Xdef close(w): # Close method +X for i in range(len(windows)): +X if windows[i] is w: +X del windows[i] +X break X -Xdef arrow(w, detail): # Arrow key method -X if detail = S.wc_left: -X w.kleft(w) -X elif detail = S.wc_up: -X w.kup(w) -X elif detail = S.wc_right: -X w.kright(w) -X elif detail = S.wc_down: -X w.kdown(w) +Xdef arrow(w, detail): # Arrow key method +X if detail = S.wc_left: +X w.kleft(w) +X elif detail = S.wc_up: +X w.kup(w) +X elif detail = S.wc_right: +X w.kright(w) +X elif detail = S.wc_down: +X w.kdown(w) X X X# Trivial methods X Xdef tab(w): w.char(w, '\t') -Xdef enter(w): w.char(w, '\n') # 'return' is a Python reserved word +Xdef enter(w): w.char(w, '\n') # 'return' is a Python reserved word Xdef backspace(w): w.char(w, '\b') Xdef m2down(w, detail): w.mdown(w, detail) Xdef m2up(w, detail): w.mup(w, detail) @@ -1042,47 +1042,47 @@ X# Tokenize a string. X# Return a list of tokens (strings). X# Xdef tokenize_string(s): -X tokens = [] -X while s: -X c = s[:1] -X if c in whitespace: -X s = s[1:] -X elif c = ';': -X s = '' -X elif c = '"': -X n = len(s) -X i = 1 -X while i < n: -X c = s[i] -X i = i+1 -X if c = '"': break -X if c = '\\': i = i+1 -X tokens.append(s[:i]) -X s = s[i:] -X elif c in operators: -X tokens.append(c) -X s = s[1:] -X else: -X n = len(s) -X i = 1 -X while i < n: -X if s[i] in separators: break -X i = i+1 -X tokens.append(s[:i]) -X s = s[i:] -X return tokens +X tokens = [] +X while s: +X c = s[:1] +X if c in whitespace: +X s = s[1:] +X elif c = ';': +X s = '' +X elif c = '"': +X n = len(s) +X i = 1 +X while i < n: +X c = s[i] +X i = i+1 +X if c = '"': break +X if c = '\\': i = i+1 +X tokens.append(s[:i]) +X s = s[i:] +X elif c in operators: +X tokens.append(c) +X s = s[1:] +X else: +X n = len(s) +X i = 1 +X while i < n: +X if s[i] in separators: break +X i = i+1 +X tokens.append(s[:i]) +X s = s[i:] +X return tokens X X X# Tokenize a whole file (given as file object, not as file name). X# Return a list of tokens (strings). X# Xdef tokenize_file(fp): -X tokens = [] -X while 1: -X line = fp.readline() -X if not line: break -X tokens = tokens + tokenize_string(line) -X return tokens +X tokens = [] +X while 1: +X line = fp.readline() +X if not line: break +X tokens = tokens + tokenize_string(line) +X return tokens X X X# Exception raised by parse_exr. @@ -1098,50 +1098,50 @@ X# and tokens contains the remaining tokens. X# May raise syntax_error. X# Xdef parse_expr(tokens): -X if (not tokens) or tokens[0] <> '(': -X raise syntax_error, 'expected "("' -X tokens = tokens[1:] -X expr = [] -X while 1: -X if not tokens: -X raise syntax_error, 'missing ")"' -X if tokens[0] = ')': -X return expr, tokens[1:] -X elif tokens[0] = '(': -X subexpr, tokens = parse_expr(tokens) -X expr.append(subexpr) -X else: -X expr.append(tokens[0]) -X tokens = tokens[1:] +X if (not tokens) or tokens[0] <> '(': +X raise syntax_error, 'expected "("' +X tokens = tokens[1:] +X expr = [] +X while 1: +X if not tokens: +X raise syntax_error, 'missing ")"' +X if tokens[0] = ')': +X return expr, tokens[1:] +X elif tokens[0] = '(': +X subexpr, tokens = parse_expr(tokens) +X expr.append(subexpr) +X else: +X expr.append(tokens[0]) +X tokens = tokens[1:] X X X# Parse a file (given as file object, not as file name). X# Return a list of parsed S-expressions found at the top level. X# Xdef parse_file(fp): -X tokens = tokenize_file(fp) -X exprlist = [] -X while tokens: -X expr, tokens = parse_expr(tokens) -X exprlist.append(expr) -X return exprlist +X tokens = tokenize_file(fp) +X exprlist = [] +X while tokens: +X expr, tokens = parse_expr(tokens) +X exprlist.append(expr) +X return exprlist X X X# EXAMPLE: X# X# The input -X# '(hip (hop hur-ray))' +X# '(hip (hop hur-ray))' X# X# passed to tokenize_string() returns the token list -X# ['(', 'hip', '(', 'hop', 'hur-ray', ')', ')'] +X# ['(', 'hip', '(', 'hop', 'hur-ray', ')', ')'] X# X# When this is passed to parse_expr() it returns the expression -X# ['hip', ['hop', 'hur-ray']] +X# ['hip', ['hop', 'hur-ray']] X# plus an empty token list (because there are no tokens left. X# X# When a file containing the example is passed to parse_file() it returns X# a list whose only element is the output of parse_expr() above: -X# [['hip', ['hop', 'hur-ray']]] +X# [['hip', ['hop', 'hur-ray']]] X X X# TOKENIZING: @@ -1150,7 +1150,7 @@ X# Comments start with semicolon (;) and continue till the end of the line. X# X# Tokens are separated by whitespace, except the following characters X# always form a separate token (outside strings): -X# ( ) ' +X# ( ) ' X# Strings are enclosed in double quotes (") and backslash (\) is used X# as escape character in strings. EOF @@ -1172,86 +1172,86 @@ X# Ignores the first part altogether if the second part is absolute X# (begins with '/'). X# Xdef cat(a, b): -X if b[:1] = '/': return b -X if a = '' or a[-1:] = '/': return a + b -X return a + '/' + b +X if b[:1] = '/': return b +X if a = '' or a[-1:] = '/': return a + b +X return a + '/' + b X X X# Split a path in head (empty or ending in '/') and tail (no '/'). X# The tail will be empty if the path ends in '/'. X# Xdef split(p): -X head, tail = '', '' -X for c in p: -X tail = tail + c -X if c = '/': -X head, tail = head + tail, '' -X return head, tail +X head, tail = '', '' +X for c in p: +X tail = tail + c +X if c = '/': +X head, tail = head + tail, '' +X return head, tail X X X# Return the tail (basename) part of a path. X# Xdef basename(p): -X return split(p)[1] +X return split(p)[1] X X X# Return the longest prefix of all list elements. X# Xdef commonprefix(m): -X if not m: return '' -X prefix = m[0] -X for item in m: -X for i in range(len(prefix)): -X if prefix[:i+1] <> item[:i+1]: -X prefix = prefix[:i] -X if i = 0: return '' -X break -X return prefix +X if not m: return '' +X prefix = m[0] +X for item in m: +X for i in range(len(prefix)): +X if prefix[:i+1] <> item[:i+1]: +X prefix = prefix[:i] +X if i = 0: return '' +X break +X return prefix X X X# Does a file/directory exist? X# Xdef exists(path): -X try: -X st = posix.stat(path) -X except posix.error: -X return 0 -X return 1 +X try: +X st = posix.stat(path) +X except posix.error: +X return 0 +X return 1 X X X# Is a path a posix directory? X# Xdef isdir(path): -X try: -X st = posix.stat(path) -X except posix.error: -X return 0 -X return stat.S_ISDIR(st[stat.ST_MODE]) +X try: +X st = posix.stat(path) +X except posix.error: +X return 0 +X return stat.S_ISDIR(st[stat.ST_MODE]) X X X# Is a path a symbolic link? X# This will always return false on systems where posix.lstat doesn't exist. X# Xdef islink(path): -X try: -X st = posix.lstat(path) -X except (posix.error, NameError): -X return 0 -X return stat.S_ISLNK(st[stat.ST_MODE]) +X try: +X st = posix.lstat(path) +X except (posix.error, NameError): +X return 0 +X return stat.S_ISLNK(st[stat.ST_MODE]) X X X_mounts = [] X Xdef _getmounts(): -X import commands, string -X mounts = [] -X data = commands.getoutput('/etc/mount') -X lines = string.splitfields(data, '\n') -X for line in lines: -X words = string.split(line) -X if len(words) >= 3 and words[1] = 'on': -X mounts.append(words[2]) -X return mounts +X import commands, string +X mounts = [] +X data = commands.getoutput('/etc/mount') +X lines = string.splitfields(data, '\n') +X for line in lines: +X words = string.split(line) +X if len(words) >= 3 and words[1] = 'on': +X mounts.append(words[2]) +X return mounts X X X# Is a path a mount point? @@ -1260,9 +1260,9 @@ X# and only if the mount table as printed by /etc/mount is correct. X# Sorry. X# Xdef ismount(path): -X if not _mounts: -X _mounts[:] = _getmounts() -X return path in _mounts +X if not _mounts: +X _mounts[:] = _getmounts() +X return path in _mounts X X X# Directory tree walk. @@ -1274,17 +1274,17 @@ X# func may modify the filenames list, to implement a filter, X# or to impose a different order of visiting. X# Xdef walk(top, func, arg): -X try: -X names = posix.listdir(top) -X except posix.error: -X return -X func(arg, top, names) -X exceptions = ('.', '..') -X for name in names: -X if name not in exceptions: -X name = cat(top, name) -X if isdir(name): -X walk(name, func, arg) +X try: +X names = posix.listdir(top) +X except posix.error: +X return +X func(arg, top, names) +X exceptions = ('.', '..') +X for name in names: +X if name not in exceptions: +X name = cat(top, name) +X if isdir(name): +X walk(name, func, arg) EOF fi if test -s 'lib/string.py' @@ -1308,119 +1308,119 @@ X X# Case conversion helpers X_caseswap = {} Xfor i in range(26): -X _caseswap[lowercase[i]] = uppercase[i] -X _caseswap[uppercase[i]] = lowercase[i] +X _caseswap[lowercase[i]] = uppercase[i] +X _caseswap[uppercase[i]] = lowercase[i] Xdel i X X# convert UPPER CASE letters to lower case Xdef lower(s): -X res = '' -X for c in s: -X if 'A' <= c <= 'Z': c = _caseswap[c] -X res = res + c -X return res +X res = '' +X for c in s: +X if 'A' <= c <= 'Z': c = _caseswap[c] +X res = res + c +X return res X X# Convert lower case letters to UPPER CASE Xdef upper(s): -X res = '' -X for c in s: -X if 'a' <= c <= 'z': c = _caseswap[c] -X res = res + c -X return res +X res = '' +X for c in s: +X if 'a' <= c <= 'z': c = _caseswap[c] +X res = res + c +X return res X X# Swap lower case letters and UPPER CASE Xdef swapcase(s): -X res = '' -X for c in s: -X if 'a' <= c <= 'z' or 'A' <= c <= 'Z': c = _caseswap[c] -X res = res + c -X return res +X res = '' +X for c in s: +X if 'a' <= c <= 'z' or 'A' <= c <= 'Z': c = _caseswap[c] +X res = res + c +X return res X X# Strip leading and trailing tabs and spaces Xdef strip(s): -X i, j = 0, len(s) -X while i < j and s[i] in whitespace: i = i+1 -X while i < j and s[j-1] in whitespace: j = j-1 -X return s[i:j] +X i, j = 0, len(s) +X while i < j and s[i] in whitespace: i = i+1 +X while i < j and s[j-1] in whitespace: j = j-1 +X return s[i:j] X X# Split a string into a list of space/tab-separated words X# NB: split(s) is NOT the same as splitfields(s, ' ')! Xdef split(s): -X res = [] -X i, n = 0, len(s) -X while i < n: -X while i < n and s[i] in whitespace: i = i+1 -X if i = n: break -X j = i -X while j < n and s[j] not in whitespace: j = j+1 -X res.append(s[i:j]) -X i = j -X return res +X res = [] +X i, n = 0, len(s) +X while i < n: +X while i < n and s[i] in whitespace: i = i+1 +X if i = n: break +X j = i +X while j < n and s[j] not in whitespace: j = j+1 +X res.append(s[i:j]) +X i = j +X return res X X# Split a list into fields separated by a given string X# NB: splitfields(s, ' ') is NOT the same as split(s)! Xdef splitfields(s, sep): -X res = [] -X ns = len(s) -X nsep = len(sep) -X i = j = 0 -X while j+nsep <= ns: -X if s[j:j+nsep] = sep: -X res.append(s[i:j]) -X i = j = j + nsep -X else: -X j = j + 1 -X res.append(s[i:]) -X return res +X res = [] +X ns = len(s) +X nsep = len(sep) +X i = j = 0 +X while j+nsep <= ns: +X if s[j:j+nsep] = sep: +X res.append(s[i:j]) +X i = j = j + nsep +X else: +X j = j + 1 +X res.append(s[i:]) +X return res X X# Find substring Xindex_error = 'substring not found in string.index' Xdef index(s, sub): -X n = len(sub) -X for i in range(len(s) + 1 - n): -X if sub = s[i:i+n]: return i -X raise index_error, (s, sub) +X n = len(sub) +X for i in range(len(s) + 1 - n): +X if sub = s[i:i+n]: return i +X raise index_error, (s, sub) X X# Convert string to integer Xatoi_error = 'non-numeric argument to string.atoi' Xdef atoi(str): -X s = str -X if s[:1] in '+-': s = s[1:] -X if not s: raise atoi_error, str -X for c in s: -X if c not in digits: raise atoi_error, str -X return eval(str) +X s = str +X if s[:1] in '+-': s = s[1:] +X if not s: raise atoi_error, str +X for c in s: +X if c not in digits: raise atoi_error, str +X return eval(str) X X# Left-justify a string Xdef ljust(s, width): -X n = len(s) -X if n >= width: return s -X return s + ' '*(width-n) +X n = len(s) +X if n >= width: return s +X return s + ' '*(width-n) X X# Right-justify a string Xdef rjust(s, width): -X n = len(s) -X if n >= width: return s -X return ' '*(width-n) + s +X n = len(s) +X if n >= width: return s +X return ' '*(width-n) + s X X# Center a string Xdef center(s, width): -X n = len(s) -X if n >= width: return s -X return ' '*((width-n)/2) + s + ' '*(width -(width-n)/2) +X n = len(s) +X if n >= width: return s +X return ' '*((width-n)/2) + s + ' '*(width -(width-n)/2) X X# Zero-fill a number, e.g., (12, 3) --> '012' and (-3, 3) --> '-03' X# Decadent feature: the argument may be a string or a number X# (Use of this is deprecated; it should be a string as with ljust c.s.) Xdef zfill(x, width): -X if type(x) = type(''): s = x -X else: s = `x` -X n = len(s) -X if n >= width: return s -X sign = '' -X if s[0] = '-': -X sign, s = '-', s[1:] -X return sign + '0'*(width-n) + s +X if type(x) = type(''): s = x +X else: s = `x` +X n = len(s) +X if n >= width: return s +X sign = '' +X if s[0] = '-': +X sign, s = '-', s[1:] +X return sign + '0'*(width-n) + s EOF fi if test -s 'src/Grammar' @@ -1431,26 +1431,26 @@ sed 's/^X//' > 'src/Grammar' << 'EOF' X# Grammar for Python, version 4 X X# Changes compared to version 3: -X# Removed 'dir' statement. -X# Function call argument is a testlist instead of exprlist. +X# Removed 'dir' statement. +X# Function call argument is a testlist instead of exprlist. X X# Changes compared to version 2: -X# The syntax of Boolean operations is changed to use more -X# conventional priorities: or < and < not. +X# The syntax of Boolean operations is changed to use more +X# conventional priorities: or < and < not. X X# Changes compared to version 1: -X# modules and scripts are unified; -X# 'quit' is gone (use ^D); -X# empty_stmt is gone, replaced by explicit NEWLINE where appropriate; -X# 'import' and 'def' aren't special any more; -X# added 'from' NAME option on import clause, and '*' to import all; -X# added class definition. +X# modules and scripts are unified; +X# 'quit' is gone (use ^D); +X# empty_stmt is gone, replaced by explicit NEWLINE where appropriate; +X# 'import' and 'def' aren't special any more; +X# added 'from' NAME option on import clause, and '*' to import all; +X# added class definition. X X# Start symbols for the grammar: -X# single_input is a single interactive statement; -X# file_input is a module or sequence of commands read from an input file; -X# expr_input is the input for the input() function; -X# eval_input is the input for the eval() function. +X# single_input is a single interactive statement; +X# file_input is a module or sequence of commands read from an input file; +X# expr_input is the input for the input() function; +X# eval_input is the input for the eval() function. X X# NB: compound_stmt in single_input is followed by extra NEWLINE! Xsingle_input: NEWLINE | simple_stmt | compound_stmt NEWLINE @@ -1464,7 +1464,7 @@ Xfplist: fpdef (',' fpdef)* Xfpdef: NAME | '(' fplist ')' X Xstmt: simple_stmt | compound_stmt -Xsimple_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt +Xsimple_stmt: expr_stmt | print_stmt | pass_stmt | del_stmt | flow_stmt | import_stmt Xexpr_stmt: (exprlist '=')* exprlist NEWLINE X# For assignments, additional restrictions enforced by the interpreter Xprint_stmt: 'print' (test ',')* [test] NEWLINE @@ -1511,12 +1511,12 @@ X/*********************************************************** XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The XNetherlands. X -X All Rights Reserved +X All Rights Reserved X -XPermission to use, copy, modify, and distribute this software and its -Xdocumentation for any purpose and without fee is hereby granted, +XPermission to use, copy, modify, and distribute this software and its +Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that -Xboth that copyright notice and this permission notice appear in +Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Stichting Mathematisch XCentrum or CWI not be used in advertising or publicity pertaining to Xdistribution of the software without specific, written prior permission. @@ -1544,101 +1544,101 @@ Xstatic void calcfirstset PROTO((grammar *, dfa *)); X Xvoid Xaddfirstsets(g) -X grammar *g; +X grammar *g; X{ -X int i; -X dfa *d; -X -X printf("Adding FIRST sets ...\n"); -X for (i = 0; i < g->g_ndfas; i++) { -X d = &g->g_dfa[i]; -X if (d->d_first == NULL) -X calcfirstset(g, d); -X } +X int i; +X dfa *d; +X +X printf("Adding FIRST sets ...\n"); +X for (i = 0; i < g->g_ndfas; i++) { +X d = &g->g_dfa[i]; +X if (d->d_first == NULL) +X calcfirstset(g, d); +X } X} X Xstatic void Xcalcfirstset(g, d) -X grammar *g; -X dfa *d; +X grammar *g; +X dfa *d; X{ -X int i, j; -X state *s; -X arc *a; -X int nsyms; -X int *sym; -X int nbits; -X static bitset dummy; -X bitset result; -X int type; -X dfa *d1; -X label *l0; -X -X if (debugging) -X printf("Calculate FIRST set for '%s'\n", d->d_name); -X -X if (dummy == NULL) -X dummy = newbitset(1); -X if (d->d_first == dummy) { -X fprintf(stderr, "Left-recursion for '%s'\n", d->d_name); -X return; -X } -X if (d->d_first != NULL) { -X fprintf(stderr, "Re-calculating FIRST set for '%s' ???\n", -X d->d_name); -X } -X d->d_first = dummy; -X -X l0 = g->g_ll.ll_label; -X nbits = g->g_ll.ll_nlabels; -X result = newbitset(nbits); -X -X sym = NEW(int, 1); -X if (sym == NULL) -X fatal("no mem for new sym in calcfirstset"); -X nsyms = 1; -X sym[0] = findlabel(&g->g_ll, d->d_type, (char *)NULL); -X -X s = &d->d_state[d->d_initial]; -X for (i = 0; i < s->s_narcs; i++) { -X a = &s->s_arc[i]; -X for (j = 0; j < nsyms; j++) { -X if (sym[j] == a->a_lbl) -X break; -X } -X if (j >= nsyms) { /* New label */ -X RESIZE(sym, int, nsyms + 1); -X if (sym == NULL) -X fatal("no mem to resize sym in calcfirstset"); -X sym[nsyms++] = a->a_lbl; -X type = l0[a->a_lbl].lb_type; -X if (ISNONTERMINAL(type)) { -X d1 = finddfa(g, type); -X if (d1->d_first == dummy) { -X fprintf(stderr, -X "Left-recursion below '%s'\n", -X d->d_name); -X } -X else { -X if (d1->d_first == NULL) -X calcfirstset(g, d1); -X mergebitset(result, d1->d_first, nbits); -X } -X } -X else if (ISTERMINAL(type)) { -X addbit(result, a->a_lbl); -X } -X } -X } -X d->d_first = result; -X if (debugging) { -X printf("FIRST set for '%s': {", d->d_name); -X for (i = 0; i < nbits; i++) { -X if (testbit(result, i)) -X printf(" %s", labelrepr(&l0[i])); -X } -X printf(" }\n"); -X } +X int i, j; +X state *s; +X arc *a; +X int nsyms; +X int *sym; +X int nbits; +X static bitset dummy; +X bitset result; +X int type; +X dfa *d1; +X label *l0; +X +X if (debugging) +X printf("Calculate FIRST set for '%s'\n", d->d_name); +X +X if (dummy == NULL) +X dummy = newbitset(1); +X if (d->d_first == dummy) { +X fprintf(stderr, "Left-recursion for '%s'\n", d->d_name); +X return; +X } +X if (d->d_first != NULL) { +X fprintf(stderr, "Re-calculating FIRST set for '%s' ???\n", +X d->d_name); +X } +X d->d_first = dummy; +X +X l0 = g->g_ll.ll_label; +X nbits = g->g_ll.ll_nlabels; +X result = newbitset(nbits); +X +X sym = NEW(int, 1); +X if (sym == NULL) +X fatal("no mem for new sym in calcfirstset"); +X nsyms = 1; +X sym[0] = findlabel(&g->g_ll, d->d_type, (char *)NULL); +X +X s = &d->d_state[d->d_initial]; +X for (i = 0; i < s->s_narcs; i++) { +X a = &s->s_arc[i]; +X for (j = 0; j < nsyms; j++) { +X if (sym[j] == a->a_lbl) +X break; +X } +X if (j >= nsyms) { /* New label */ +X RESIZE(sym, int, nsyms + 1); +X if (sym == NULL) +X fatal("no mem to resize sym in calcfirstset"); +X sym[nsyms++] = a->a_lbl; +X type = l0[a->a_lbl].lb_type; +X if (ISNONTERMINAL(type)) { +X d1 = finddfa(g, type); +X if (d1->d_first == dummy) { +X fprintf(stderr, +X "Left-recursion below '%s'\n", +X d->d_name); +X } +X else { +X if (d1->d_first == NULL) +X calcfirstset(g, d1); +X mergebitset(result, d1->d_first, nbits); +X } +X } +X else if (ISTERMINAL(type)) { +X addbit(result, a->a_lbl); +X } +X } +X } +X d->d_first = result; +X if (debugging) { +X printf("FIRST set for '%s': {", d->d_name); +X for (i = 0; i < nbits; i++) { +X if (testbit(result, i)) +X printf(" %s", labelrepr(&l0[i])); +X } +X printf(" }\n"); +X } X} EOF fi @@ -1651,12 +1651,12 @@ X/*********************************************************** XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The XNetherlands. X -X All Rights Reserved +X All Rights Reserved X -XPermission to use, copy, modify, and distribute this software and its -Xdocumentation for any purpose and without fee is hereby granted, +XPermission to use, copy, modify, and distribute this software and its +Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that -Xboth that copyright notice and this permission notice appear in +Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Stichting Mathematisch XCentrum or CWI not be used in advertising or publicity pertaining to Xdistribution of the software without specific, written prior permission. @@ -1674,22 +1674,22 @@ X X/* Frame object interface */ X Xtypedef struct { -X int b_type; /* what kind of block this is */ -X int b_handler; /* where to jump to find handler */ -X int b_level; /* value stack level to pop to */ +X int b_type; /* what kind of block this is */ +X int b_handler; /* where to jump to find handler */ +X int b_level; /* value stack level to pop to */ X} block; X Xtypedef struct _frame { -X OB_HEAD -X struct _frame *f_back; /* previous frame, or NULL */ -X codeobject *f_code; /* code segment */ -X object *f_globals; /* global symbol table (dictobject) */ -X object *f_locals; /* local symbol table (dictobject) */ -X object **f_valuestack; /* malloc'ed array */ -X block *f_blockstack; /* malloc'ed array */ -X int f_nvalues; /* size of f_valuestack */ -X int f_nblocks; /* size of f_blockstack */ -X int f_iblock; /* index in f_blockstack */ +X OB_HEAD +X struct _frame *f_back; /* previous frame, or NULL */ +X codeobject *f_code; /* code segment */ +X object *f_globals; /* global symbol table (dictobject) */ +X object *f_locals; /* local symbol table (dictobject) */ +X object **f_valuestack; /* malloc'ed array */ +X block *f_blockstack; /* malloc'ed array */ +X int f_nvalues; /* size of f_valuestack */ +X int f_nblocks; /* size of f_blockstack */ +X int f_iblock; /* index in f_blockstack */ X} frameobject; X X @@ -1700,7 +1700,7 @@ X X#define is_frameobject(op) ((op)->ob_type == &Frametype) X Xframeobject * newframeobject PROTO( -X (frameobject *, codeobject *, object *, object *, int, int)); +X (frameobject *, codeobject *, object *, object *, int, int)); X X X/* The rest of the interface is specific for frame objects */ @@ -1719,8 +1719,8 @@ X#define GETUSTRINGVALUE(s) ((unsigned char *)GETSTRINGVALUE(s)) X X/* Code access macros */ X -X#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i))) -X#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i))) +X#define Getconst(f, i) (GETITEM((f)->f_code->co_consts, (i))) +X#define Getname(f, i) (GETITEMNAME((f)->f_code->co_names, (i))) X X X/* Block management functions */ @@ -1738,12 +1738,12 @@ X/*********************************************************** XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The XNetherlands. X -X All Rights Reserved +X All Rights Reserved X -XPermission to use, copy, modify, and distribute this software and its -Xdocumentation for any purpose and without fee is hereby granted, +XPermission to use, copy, modify, and distribute this software and its +Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that -Xboth that copyright notice and this permission notice appear in +Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Stichting Mathematisch XCentrum or CWI not be used in advertising or publicity pertaining to Xdistribution of the software without specific, written prior permission. @@ -1765,46 +1765,46 @@ X X#include "structmember.h" X Xtypedef struct { -X OB_HEAD -X object *func_code; -X object *func_globals; +X OB_HEAD +X object *func_code; +X object *func_globals; X} funcobject; X Xobject * Xnewfuncobject(code, globals) -X object *code; -X object *globals; +X object *code; +X object *globals; X{ -X funcobject *op = NEWOBJ(funcobject, &Functype); -X if (op != NULL) { -X INCREF(code); -X op->func_code = code; -X INCREF(globals); -X op->func_globals = globals; -X } -X return (object *)op; +X funcobject *op = NEWOBJ(funcobject, &Functype); +X if (op != NULL) { +X INCREF(code); +X op->func_code = code; +X INCREF(globals); +X op->func_globals = globals; +X } +X return (object *)op; X} X Xobject * Xgetfunccode(op) -X object *op; +X object *op; X{ -X if (!is_funcobject(op)) { -X err_badcall(); -X return NULL; -X } -X return ((funcobject *) op) -> func_code; +X if (!is_funcobject(op)) { +X err_badcall(); +X return NULL; +X } +X return ((funcobject *) op) -> func_code; X} X Xobject * Xgetfuncglobals(op) -X object *op; +X object *op; X{ -X if (!is_funcobject(op)) { -X err_badcall(); -X return NULL; -X } -X return ((funcobject *) op) -> func_globals; +X if (!is_funcobject(op)) { +X err_badcall(); +X return NULL; +X } +X return ((funcobject *) op) -> func_globals; X} X X/* Methods */ @@ -1812,40 +1812,40 @@ X X#define OFF(x) offsetof(funcobject, x) X Xstatic struct memberlist func_memberlist[] = { -X {"func_code", T_OBJECT, OFF(func_code)}, -X {"func_globals",T_OBJECT, OFF(func_globals)}, -X {NULL} /* Sentinel */ +X {"func_code", T_OBJECT, OFF(func_code)}, +X {"func_globals",T_OBJECT, OFF(func_globals)}, +X {NULL} /* Sentinel */ X}; X Xstatic object * Xfunc_getattr(op, name) -X funcobject *op; -X char *name; +X funcobject *op; +X char *name; X{ -X return getmember((char *)op, func_memberlist, name); +X return getmember((char *)op, func_memberlist, name); X} X Xstatic void Xfunc_dealloc(op) -X funcobject *op; +X funcobject *op; X{ -X DECREF(op->func_code); -X DECREF(op->func_globals); -X DEL(op); +X DECREF(op->func_code); +X DECREF(op->func_globals); +X DEL(op); X} X Xtypeobject Functype = { -X OB_HEAD_INIT(&Typetype) -X 0, -X "function", -X sizeof(funcobject), -X 0, -X func_dealloc, /*tp_dealloc*/ -X 0, /*tp_print*/ -X func_getattr, /*tp_getattr*/ -X 0, /*tp_setattr*/ -X 0, /*tp_compare*/ -X 0, /*tp_repr*/ +X OB_HEAD_INIT(&Typetype) +X 0, +X "function", +X sizeof(funcobject), +X 0, +X func_dealloc, /*tp_dealloc*/ +X 0, /*tp_print*/ +X func_getattr, /*tp_getattr*/ +X 0, /*tp_setattr*/ +X 0, /*tp_compare*/ +X 0, /*tp_repr*/ X}; EOF fi @@ -1858,12 +1858,12 @@ X/*********************************************************** XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The XNetherlands. X -X All Rights Reserved +X All Rights Reserved X -XPermission to use, copy, modify, and distribute this software and its -Xdocumentation for any purpose and without fee is hereby granted, +XPermission to use, copy, modify, and distribute this software and its +Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that -Xboth that copyright notice and this permission notice appear in +Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Stichting Mathematisch XCentrum or CWI not be used in advertising or publicity pertaining to Xdistribution of the software without specific, written prior permission. @@ -1885,58 +1885,58 @@ X X/* A label of an arc */ X Xtypedef struct _label { -X int lb_type; -X char *lb_str; +X int lb_type; +X char *lb_str; X} label; X -X#define EMPTY 0 /* Label number 0 is by definition the empty label */ +X#define EMPTY 0 /* Label number 0 is by definition the empty label */ X X/* A list of labels */ X Xtypedef struct _labellist { -X int ll_nlabels; -X label *ll_label; +X int ll_nlabels; +X label *ll_label; X} labellist; X X/* An arc from one state to another */ X Xtypedef struct _arc { -X short a_lbl; /* Label of this arc */ -X short a_arrow; /* State where this arc goes to */ +X short a_lbl; /* Label of this arc */ +X short a_arrow; /* State where this arc goes to */ X} arc; X X/* A state in a DFA */ X Xtypedef struct _state { -X int s_narcs; -X arc *s_arc; /* Array of arcs */ -X -X /* Optional accelerators */ -X int s_lower; /* Lowest label index */ -X int s_upper; /* Highest label index */ -X int *s_accel; /* Accelerator */ -X int s_accept; /* Nonzero for accepting state */ +X int s_narcs; +X arc *s_arc; /* Array of arcs */ +X +X /* Optional accelerators */ +X int s_lower; /* Lowest label index */ +X int s_upper; /* Highest label index */ +X int *s_accel; /* Accelerator */ +X int s_accept; /* Nonzero for accepting state */ X} state; X X/* A DFA */ X Xtypedef struct _dfa { -X int d_type; /* Non-terminal this represents */ -X char *d_name; /* For printing */ -X int d_initial; /* Initial state */ -X int d_nstates; -X state *d_state; /* Array of states */ -X bitset d_first; +X int d_type; /* Non-terminal this represents */ +X char *d_name; /* For printing */ +X int d_initial; /* Initial state */ +X int d_nstates; +X state *d_state; /* Array of states */ +X bitset d_first; X} dfa; X X/* A grammar */ X Xtypedef struct _grammar { -X int g_ndfas; -X dfa *g_dfa; /* Array of DFAs */ -X labellist g_ll; -X int g_start; /* Start symbol of the grammar */ -X int g_accel; /* Set if accelerators present */ +X int g_ndfas; +X dfa *g_dfa; /* Array of DFAs */ +X labellist g_ll; +X int g_start; /* Start symbol of the grammar */ +X int g_accel; /* Set if accelerators present */ X} grammar; X X/* FUNCTIONS */ @@ -1970,12 +1970,12 @@ X/*********************************************************** XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The XNetherlands. X -X All Rights Reserved +X All Rights Reserved X -XPermission to use, copy, modify, and distribute this software and its -Xdocumentation for any purpose and without fee is hereby granted, +XPermission to use, copy, modify, and distribute this software and its +Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that -Xboth that copyright notice and this permission notice appear in +Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Stichting Mathematisch XCentrum or CWI not be used in advertising or publicity pertaining to Xdistribution of the software without specific, written prior permission. @@ -1995,11 +1995,11 @@ X X/* X123456789-123456789-123456789-123456789-123456789-123456789-123456789-12 X -Xintobject represents a (long) integer. This is an immutable object; +Xintobject represents a (long) integer. This is an immutable object; Xan integer cannot change its value after creation. X XThere are functions to create new integer objects, to test an object -Xfor integer-ness, and to get the integer value. The latter functions +Xfor integer-ness, and to get the integer value. The latter functions Xreturns -1 and sets errno to EBADF if the object is not an intobject. XNone of the functions should be applied to nil objects. X @@ -2008,8 +2008,8 @@ XTrueObject and FalseObject below; don't use this. X*/ X Xtypedef struct { -X OB_HEAD -X long ob_ival; +X OB_HEAD +X long ob_ival; X} intobject; X Xextern typeobject Inttype; @@ -2049,12 +2049,12 @@ X/*********************************************************** XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The XNetherlands. X -X All Rights Reserved +X All Rights Reserved X -XPermission to use, copy, modify, and distribute this software and its -Xdocumentation for any purpose and without fee is hereby granted, +XPermission to use, copy, modify, and distribute this software and its +Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that -Xboth that copyright notice and this permission notice appear in +Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Stichting Mathematisch XCentrum or CWI not be used in advertising or publicity pertaining to Xdistribution of the software without specific, written prior permission. @@ -2083,12 +2083,12 @@ X Xint Xintrcheck() X{ -X int interrupted = 0; -X while (kbhit()) { -X if (getch() == '\003') -X interrupted = 1; -X } -X return interrupted; +X int interrupted = 0; +X while (kbhit()) { +X if (getch() == '\003') +X interrupted = 1; +X } +X return interrupted; X} X X#define OK @@ -2099,7 +2099,7 @@ X X#ifdef THINK_C X X/* This is for THINK C 4.0. -X For 3.0, you may have to remove the signal stuff. */ +X For 3.0, you may have to remove the signal stuff. */ X X#include X#include @@ -2109,44 +2109,44 @@ Xstatic int interrupted; X Xstatic SIGTYPE Xintcatcher(sig) -X int sig; +X int sig; X{ -X interrupted = 1; -X signal(SIGINT, intcatcher); +X interrupted = 1; +X signal(SIGINT, intcatcher); X} X Xvoid Xinitintr() X{ -X if (signal(SIGINT, SIG_IGN) != SIG_IGN) -X signal(SIGINT, intcatcher); +X if (signal(SIGINT, SIG_IGN) != SIG_IGN) +X signal(SIGINT, intcatcher); X} X Xint Xintrcheck() X{ -X register EvQElPtr q; -X -X /* This is like THINK C 4.0's . -X I'm not sure why FlushEvents must be called from asm{}. */ -X for (q = (EvQElPtr)EventQueue.qHead; q; q = (EvQElPtr)q->qLink) { -X if (q->evtQWhat == keyDown && -X (char)q->evtQMessage == '.' && -X (q->evtQModifiers & cmdKey) != 0) { -X -X asm { -X moveq #keyDownMask,d0 -X _FlushEvents -X } -X interrupted = 1; -X break; -X } -X } -X if (interrupted) { -X interrupted = 0; -X return 1; -X } -X return 0; +X register EvQElPtr q; +X +X /* This is like THINK C 4.0's . +X I'm not sure why FlushEvents must be called from asm{}. */ +X for (q = (EvQElPtr)EventQueue.qHead; q; q = (EvQElPtr)q->qLink) { +X if (q->evtQWhat == keyDown && +X (char)q->evtQMessage == '.' && +X (q->evtQModifiers & cmdKey) != 0) { +X +X asm { +X moveq #keyDownMask,d0 +X _FlushEvents +X } +X interrupted = 1; +X break; +X } +X } +X if (interrupted) { +X interrupted = 0; +X return 1; +X } +X return 0; X} X X#define OK @@ -2166,26 +2166,26 @@ Xstatic int interrupted; X Xstatic SIGTYPE Xintcatcher(sig) -X int sig; +X int sig; X{ -X interrupted = 1; -X signal(SIGINT, intcatcher); +X interrupted = 1; +X signal(SIGINT, intcatcher); X} X Xvoid Xinitintr() X{ -X if (signal(SIGINT, SIG_IGN) != SIG_IGN) -X signal(SIGINT, intcatcher); +X if (signal(SIGINT, SIG_IGN) != SIG_IGN) +X signal(SIGINT, intcatcher); X} X Xint Xintrcheck() X{ -X if (!interrupted) -X return 0; -X interrupted = 0; -X return 1; +X if (!interrupted) +X return 0; +X interrupted = 0; +X return 1; X} X X#endif /* !OK */ @@ -2200,12 +2200,12 @@ X/*********************************************************** XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The XNetherlands. X -X All Rights Reserved +X All Rights Reserved X -XPermission to use, copy, modify, and distribute this software and its -Xdocumentation for any purpose and without fee is hereby granted, +XPermission to use, copy, modify, and distribute this software and its +Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that -Xboth that copyright notice and this permission notice appear in +Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Stichting Mathematisch XCentrum or CWI not be used in advertising or publicity pertaining to Xdistribution of the software without specific, written prior permission. @@ -2240,94 +2240,94 @@ Xint debugging = 1; X XFILE *getopenfile() X{ -X char buf[256]; -X char *p; -X FILE *fp; -X for (;;) { -X fprintf(stderr, "File name: "); -X if (fgets(buf, sizeof buf, stdin) == NULL) { -X fprintf(stderr, "EOF\n"); -X exit(1); -X } -X p = strchr(buf, '\n'); -X if (p != NULL) -X *p = '\0'; -X if ((fp = fopen(buf, "r")) != NULL) -X break; -X fprintf(stderr, "Sorry, try again.\n"); -X } -X return fp; +X char buf[256]; +X char *p; +X FILE *fp; +X for (;;) { +X fprintf(stderr, "File name: "); +X if (fgets(buf, sizeof buf, stdin) == NULL) { +X fprintf(stderr, "EOF\n"); +X exit(1); +X } +X p = strchr(buf, '\n'); +X if (p != NULL) +X *p = '\0'; +X if ((fp = fopen(buf, "r")) != NULL) +X break; +X fprintf(stderr, "Sorry, try again.\n"); +X } +X return fp; X} X Xmain() X{ -X FILE *fp; -X _profile = 0; -X fp = getopenfile(); +X FILE *fp; +X _profile = 0; +X fp = getopenfile(); X#if 0 -X askgo("Start tokenizing"); -X runtokenizer(fp); -X fseek(fp, 0L, 0); +X askgo("Start tokenizing"); +X runtokenizer(fp); +X fseek(fp, 0L, 0); X#endif -X if (!gram.g_accel) -X addaccelerators(&gram); -X askgo("Start parsing"); -X _profile = 1; -X runparser(fp); -X _profile = 0; -X freopen("prof.out", "w", stdout); -X DumpProfile(); -X fflush(stdout); -X exit(0); +X if (!gram.g_accel) +X addaccelerators(&gram); +X askgo("Start parsing"); +X _profile = 1; +X runparser(fp); +X _profile = 0; +X freopen("prof.out", "w", stdout); +X DumpProfile(); +X fflush(stdout); +X exit(0); X} X Xstatic int Xruntokenizer(fp) -X FILE *fp; +X FILE *fp; X{ -X struct tok_state *tok; -X tok = tok_setupf(fp, "Tokenizing", "."); -X for (;;) { -X char *a, *b; -X register char *str; -X register int len; -X (void) tok_get(tok, &a, &b); -X if (tok->done != E_OK) -X break; -X len = b - a; -X str = NEW(char, len + 1); -X if (str == NULL) { -X fprintf(stderr, "no mem for next token"); -X break; -X } -X strncpy(str, a, len); -X str[len] = '\0'; -X } -X fprintf(stderr, "done (%d)\n", tok->done); +X struct tok_state *tok; +X tok = tok_setupf(fp, "Tokenizing", "."); +X for (;;) { +X char *a, *b; +X register char *str; +X register int len; +X (void) tok_get(tok, &a, &b); +X if (tok->done != E_OK) +X break; +X len = b - a; +X str = NEW(char, len + 1); +X if (str == NULL) { +X fprintf(stderr, "no mem for next token"); +X break; +X } +X strncpy(str, a, len); +X str[len] = '\0'; +X } +X fprintf(stderr, "done (%d)\n", tok->done); X} X Xstatic Xrunparser(fp, start) -X FILE *fp; +X FILE *fp; X{ -X node *n; -X int ret; -X ret = parsefile(fp, &gram, module_input, "Parsing", ".", &n); -X fprintf(stderr, "done (%d)\n", ret); +X node *n; +X int ret; +X ret = parsefile(fp, &gram, module_input, "Parsing", ".", &n); +X fprintf(stderr, "done (%d)\n", ret); X#if 0 -X _profile = 0; -X if (ret == E_DONE) -X listtree(n); +X _profile = 0; +X if (ret == E_DONE) +X listtree(n); X#endif X} X Xstatic int Xaskgo(prompt) -X char *prompt; +X char *prompt; X{ -X char buf[256]; -X fprintf(stderr, "%s: hit return when ready: ", prompt); -X fgets(buf, sizeof buf, stdin); +X char buf[256]; +X fprintf(stderr, "%s: hit return when ready: ", prompt); +X fgets(buf, sizeof buf, stdin); X} EOF fi @@ -2340,12 +2340,12 @@ X/*********************************************************** XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The XNetherlands. X -X All Rights Reserved +X All Rights Reserved X -XPermission to use, copy, modify, and distribute this software and its -Xdocumentation for any purpose and without fee is hereby granted, +XPermission to use, copy, modify, and distribute this software and its +Xdocumentation for any purpose and without fee is hereby granted, Xprovided that the above copyright notice appear in all copies and that -Xboth that copyright notice and this permission notice appear in +Xboth that copyright notice and this permission notice appear in Xsupporting documentation, and that the names of Stichting Mathematisch XCentrum or CWI not be used in advertising or publicity pertaining to Xdistribution of the software without specific, written prior permission. @@ -2361,104 +2361,104 @@ X X******************************************************************/ X X/* -X** strtol -X** This is a general purpose routine for converting -X** an ascii string to an integer in an arbitrary base. -X** Leading white space is ignored, if 'base' is zero -X** it looks for a leading 0, 0x or 0X to tell which -X** base. If these are absent it defaults to 10. -X** Base must be between 0 and 36. -X** If 'ptr' is non-NULL it will contain a pointer to -X** the end of the scan. -X** Errors due to bad pointers will probably result in -X** exceptions - we don't check for them. +X** strtol +X** This is a general purpose routine for converting +X** an ascii string to an integer in an arbitrary base. +X** Leading white space is ignored, if 'base' is zero +X** it looks for a leading 0, 0x or 0X to tell which +X** base. If these are absent it defaults to 10. +X** Base must be between 0 and 36. +X** If 'ptr' is non-NULL it will contain a pointer to +X** the end of the scan. +X** Errors due to bad pointers will probably result in +X** exceptions - we don't check for them. X*/ X X#include "ctype.h" X Xlong Xstrtol(str, ptr, base) -Xregister char * str; -Xchar ** ptr; -Xint base; +Xregister char * str; +Xchar ** ptr; +Xint base; X{ -X register long result; /* return value of the function */ -X register int c; /* current input character */ -X int minus; /* true if a leading minus was found */ +X register long result; /* return value of the function */ +X register int c; /* current input character */ +X int minus; /* true if a leading minus was found */ X -X result = 0; -X minus = 0; +X result = 0; +X minus = 0; X X/* catch silly bases */ -X if (base < 0 || base > 36) -X { -X if (ptr) -X *ptr = str; -X return result; -X } +X if (base < 0 || base > 36) +X { +X if (ptr) +X *ptr = str; +X return result; +X } X X/* skip leading white space */ -X while (*str && isspace(*str)) -X str++; +X while (*str && isspace(*str)) +X str++; X X/* check for optional leading minus sign */ -X if (*str == '-') -X { -X minus = 1; -X str++; -X } +X if (*str == '-') +X { +X minus = 1; +X str++; +X } X X/* check for leading 0 or 0x for auto-base or base 16 */ -X switch (base) -X { -X case 0: /* look for leading 0, 0x or 0X */ -X if (*str == '0') -X { -X str++; -X if (*str == 'x' || *str == 'X') -X { -X str++; -X base = 16; -X } -X else -X base = 8; -X } -X else -X base = 10; -X break; -X -X case 16: /* skip leading 0x or 0X */ -X if (*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X')) -X str += 2; -X break; -X } +X switch (base) +X { +X case 0: /* look for leading 0, 0x or 0X */ +X if (*str == '0') +X { +X str++; +X if (*str == 'x' || *str == 'X') +X { +X str++; +X base = 16; +X } +X else +X base = 8; +X } +X else +X base = 10; +X break; +X +X case 16: /* skip leading 0x or 0X */ +X if (*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X')) +X str += 2; +X break; +X } X X/* do the conversion */ -X while (c = *str) -X { -X if (isdigit(c) && c - '0' < base) -X c -= '0'; -X else -X { -X if (isupper(c)) -X c = tolower(c); -X if (c >= 'a' && c <= 'z') -X c -= 'a' - 10; -X else /* non-"digit" character */ -X break; -X if (c >= base) /* non-"digit" character */ -X break; -X } -X result = result * base + c; -X str++; -X } +X while (c = *str) +X { +X if (isdigit(c) && c - '0' < base) +X c -= '0'; +X else +X { +X if (isupper(c)) +X c = tolower(c); +X if (c >= 'a' && c <= 'z') +X c -= 'a' - 10; +X else /* non-"digit" character */ +X break; +X if (c >= base) /* non-"digit" character */ +X break; +X } +X result = result * base + c; +X str++; +X } X X/* set pointer to point to the last character scanned */ -X if (ptr) -X *ptr = str; -X return minus ? -result : result; +X if (ptr) +X *ptr = str; +X return minus ? -result : result; X} EOF fi echo 'Part 17 out of 21 of pack.out complete.' -exit 0 +exit 0 \ No newline at end of file -- cgit v1.2.3