home *** CD-ROM | disk | FTP | other *** search
/ Source Code 1992 March / Source_Code_CD-ROM_Walnut_Creek_March_1992.iso / usenet / altsrcs / 2 / 2811 < prev    next >
Internet Message Format  |  1991-02-19  |  44KB

  1. From: guido@cwi.nl (Guido van Rossum)
  2. Newsgroups: alt.sources
  3. Subject: Python 0.9.1 part 21/21
  4. Message-ID: <2983@charon.cwi.nl>
  5. Date: 19 Feb 91 17:42:58 GMT
  6.  
  7. : This is a shell archive.
  8. : Extract with 'sh this_file'.
  9. :
  10. : Extract part 01 first since it makes all directories
  11. echo 'Start of pack.out, part 21 out of 21:'
  12. if test -s 'demo/README'
  13. then echo '*** I will not over-write existing file demo/README'
  14. else
  15. echo 'x - demo/README'
  16. sed 's/^X//' > 'demo/README' << 'EOF'
  17. XThis directory contains various demonstrations of what you can do with
  18. XPython.  The demos are grouped sub(sub*)directories according to
  19. Xrequired optional built-in modules.
  20. X
  21. Xscripts        Some useful Python scripts that I put in my bin
  22. X        directory.  No optional built-in modules meeded.
  23. X
  24. Xsgi        Demos that only run on Silicon Graphics machines.
  25. X        Require the built-in modules 'audio' and/or 'gl'.
  26. X
  27. Xstdwin        Demos that use the STDWIN library.  Require the 'stdwin'
  28. X        built-in module.
  29. X
  30. XWARNING: some scripts are executable and have a first line saying
  31. X
  32. X    #! /ufs/guido/bin/sgi/python
  33. X
  34. XThis is unlikely to give good results anywhere else except in my
  35. Xoffice.  Edit the first line before installing such scripts; to try
  36. Xthem out, you can just say "python file.py".  (The .py suffix is not
  37. Xnecessary in this case, but makes it possible to debug the modules
  38. Xinteractively by importing them.)
  39. EOF
  40. fi
  41. if test -s 'demo/scripts/findlinksto.py'
  42. then echo '*** I will not over-write existing file demo/scripts/findlinksto.py'
  43. else
  44. echo 'x - demo/scripts/findlinksto.py'
  45. sed 's/^X//' > 'demo/scripts/findlinksto.py' << 'EOF'
  46. X#! /ufs/guido/bin/sgi/python
  47. X
  48. X# findlinksto
  49. X#
  50. X# find symbolic links to a given path
  51. X
  52. Ximport posix, path, sys
  53. X
  54. Xdef visit(pattern, dirname, names):
  55. X    if path.islink(dirname):
  56. X        names[:] = []
  57. X        return
  58. X    if path.ismount(dirname):
  59. X        print 'descend into', dirname
  60. X    n = len(pattern)
  61. X    for name in names:
  62. X        name = path.cat(dirname, name)
  63. X        try:
  64. X            linkto = posix.readlink(name)
  65. X            if linkto[:n] = pattern:
  66. X                print name, '->', linkto
  67. X        except posix.error:
  68. X            pass
  69. X
  70. Xdef main(pattern, args):
  71. X    for dirname in args:
  72. X        path.walk(dirname, visit, pattern)
  73. X
  74. Xmain(sys.argv[1], sys.argv[2:])
  75. EOF
  76. chmod +x 'demo/scripts/findlinksto.py'
  77. fi
  78. if test -s 'demo/scripts/suff.py'
  79. then echo '*** I will not over-write existing file demo/scripts/suff.py'
  80. else
  81. echo 'x - demo/scripts/suff.py'
  82. sed 's/^X//' > 'demo/scripts/suff.py' << 'EOF'
  83. X#! /ufs/guido/bin/sgi/python
  84. X
  85. X# suff
  86. X#
  87. X# show different suffixes amongst arguments
  88. X
  89. Ximport sys
  90. X
  91. Xdef main():
  92. X    files = sys.argv[1:]
  93. X    suffixes = {}
  94. X    for file in files:
  95. X        suff = getsuffix(file)
  96. X        if not suffixes.has_key(suff):
  97. X            suffixes[suff] = []
  98. X        suffixes[suff].append(file)
  99. X    keys = suffixes.keys()
  100. X    keys.sort()
  101. X    for suff in keys:
  102. X        print `suff`, len(suffixes[suff])
  103. X
  104. Xdef getsuffix(file):
  105. X    suff = ''
  106. X    for i in range(len(file)):
  107. X        if file[i] = '.':
  108. X            suff = file[i:]
  109. X    return suff
  110. X
  111. Xmain()
  112. EOF
  113. chmod +x 'demo/scripts/suff.py'
  114. fi
  115. if test -s 'demo/sgi/README'
  116. then echo '*** I will not over-write existing file demo/sgi/README'
  117. else
  118. echo 'x - demo/sgi/README'
  119. sed 's/^X//' > 'demo/sgi/README' << 'EOF'
  120. XDemonstrations of Python that use various features of the Silicon
  121. XGraphics IRIS machines.
  122. X
  123. Xaudio        Demonstrations of the audio capabilities of the 4D/25.
  124. X        Require the built-in module 'audio'.
  125. X
  126. Xaudio_stdwin    Window-based demonstrations the audio capabilities of
  127. X        the 4D/25. Require the built-in modules 'stdwin' and
  128. X        'audio'.
  129. X
  130. Xgl        Demonstrations of the Graphics Library (GL).
  131. X        Require the built-in module 'gl'.
  132. X
  133. Xgl_panel    Demonstrations of the Panel Library by NASA Ames.
  134. X        Require the built-in modules 'gl' and 'pnl'.
  135. EOF
  136. fi
  137. if test -s 'demo/sgi/audio/README'
  138. then echo '*** I will not over-write existing file demo/sgi/audio/README'
  139. else
  140. echo 'x - demo/sgi/audio/README'
  141. sed 's/^X//' > 'demo/sgi/audio/README' << 'EOF'
  142. XPrograms that demonstrate the use of the audio device on the SGI 4D/25.
  143. XThese require the built-in module 'audio'.
  144. X
  145. Xplay        Read a sound sample from a file and play it through the
  146. X        speaker.  Options to set volume, sampling rate etc.
  147. EOF
  148. fi
  149. if test -s 'demo/sgi/audio_stdwin/vumeter.py'
  150. then echo '*** I will not over-write existing file demo/sgi/audio_stdwin/vumeter.py'
  151. else
  152. echo 'x - demo/sgi/audio_stdwin/vumeter.py'
  153. sed 's/^X//' > 'demo/sgi/audio_stdwin/vumeter.py' << 'EOF'
  154. X#! /ufs/guido/bin/sgi/python
  155. X
  156. Ximport audio
  157. Ximport stdwin
  158. X
  159. Xfrom VUMeter import VUMeter
  160. Xfrom WindowParent import WindowParent
  161. Ximport MainLoop
  162. X
  163. XNBUFS=20
  164. XBUFSIZE = NBUFS*48
  165. XSCALE=128
  166. X
  167. Xclass MyVUMeter() = VUMeter():
  168. X    def init_reactivity(self):
  169. X        self.parent.need_mouse(self)
  170. X    def mouse_down(self, detail):
  171. X        if self.enabled:
  172. X            self.stop()
  173. X        else:
  174. X            self.start()
  175. X    def mouse_move(self, detail): pass
  176. X    def mouse_up(self, detail): pass
  177. X
  178. Xdef main():
  179. X    audio.setrate(3)
  180. X    audio.setoutgain(0)
  181. X    w = WindowParent().create('VU Meter', (200, 100))
  182. X    v = MyVUMeter().define(w)
  183. X    v.start()
  184. X    w.realize()
  185. X    while 1:
  186. X        w.dispatch(stdwin.getevent())
  187. X
  188. Xmain()
  189. EOF
  190. chmod +x 'demo/sgi/audio_stdwin/vumeter.py'
  191. fi
  192. if test -s 'demo/sgi/gl/README'
  193. then echo '*** I will not over-write existing file demo/sgi/gl/README'
  194. else
  195. echo 'x - demo/sgi/gl/README'
  196. sed 's/^X//' > 'demo/sgi/gl/README' << 'EOF'
  197. XThese demos run only on SGI machines and require the 'gl' built-in module.
  198. XThe demonstrate the abilities of SGI's GL library as well as the ease of
  199. XGL programming in Python.  Most demos require the Z-buffer (aka
  200. X24-bitplane) option.
  201. X
  202. Xbackface    Demonstrates the 'backface' GL function.
  203. X
  204. Xkites        Show 3 flying kites.  Demonstrates the rendering speed
  205. X        obtainable by Python programs.
  206. X
  207. Xmclock        A colorful clock with more options than you can
  208. X        remember.  Works on 8-bit machines (but allows more
  209. X        colors on 24-bit machines).
  210. X
  211. Xmixing        Demonstrates the effect of color mixing: through
  212. X        frequent color switching it gives the effect of white
  213. X        light.
  214. X
  215. Xnurbs        A simple demonstration of the 'nurbs' GL functions.
  216. X
  217. Xzrgb        Displays a 3-D Gouraud-shaded figure which can be moved
  218. X        around with the mouse.
  219. EOF
  220. fi
  221. if test -s 'demo/sgi/gl_panel/README'
  222. then echo '*** I will not over-write existing file demo/sgi/gl_panel/README'
  223. else
  224. echo 'x - demo/sgi/gl_panel/README'
  225. sed 's/^X//' > 'demo/sgi/gl_panel/README' << 'EOF'
  226. XThis directory contains demos that use the Panel Library by NASA Ames.
  227. XThey only run on SGI machines and require the 'pnl' and 'gl' built-in
  228. Xmodules.  Each subdirectory contains one demo.
  229. X
  230. Xapanel        A trivial user interface to the audio capabilities of
  231. X        the 4D/25 (Personal IRIS).  Lets you record a sample and
  232. X        play it back at different volumes.  Requires the 'audio'
  233. X        built-in module.
  234. X
  235. Xflying        A large demonstration that can display several
  236. X        differently shaped objects through space.  Control
  237. X        panels let you manipulate light sources, material
  238. X        properties and drawing modes.
  239. X
  240. Xnurbs        A demo of the capabilities of the GL 'nurbs' functions
  241. X        that can display the control points.  (It was intended
  242. X        to let you move these as well, but there was a problem
  243. X        with the mapping of mouse movements in a 3-D world.)
  244. X
  245. Xtwoview        A demo of GL's transformation primitives.  Two views on
  246. X        a scene are given, and the position and orientation of a
  247. X        viewer in one of the views can be changed through
  248. X        various buttons and dials in a control panel.
  249. EOF
  250. fi
  251. if test -s 'demo/sgi/gl_panel/apanel/apanel.py'
  252. then echo '*** I will not over-write existing file demo/sgi/gl_panel/apanel/apanel.py'
  253. else
  254. echo 'x - demo/sgi/gl_panel/apanel/apanel.py'
  255. sed 's/^X//' > 'demo/sgi/gl_panel/apanel/apanel.py' << 'EOF'
  256. X#! /ufs/guido/bin/sgi/python
  257. X
  258. X# A (too) trivial control panel to record a sound sample and play it back.
  259. X# Requires the audio built-in module.
  260. X# Requires the NASA AMES Panel Library.
  261. X
  262. Ximport sys
  263. X
  264. Ximport gl
  265. Ximport panel
  266. X
  267. Xpanel.block(1)
  268. X
  269. Ximport audio
  270. X
  271. Xdef main():
  272. X    gl.foreground()
  273. X    gl.noport()
  274. X    #gl.prefposition(700, 850, 950, 970)
  275. X    wid = gl.winopen('audio demo')
  276. X    #
  277. X    panels = panel.defpanellist('apanel.s') # XXX
  278. X    p = panels[0]
  279. X    p.playbackbutton.back = p
  280. X    p.recordbutton.back = p
  281. X    p.sample = ''
  282. X    #
  283. X    def quit(a):
  284. X        sys.exit(0)
  285. X    #
  286. X    p.quitbutton.downfunc = quit
  287. X    #
  288. X    def playback(a):
  289. X        p = a.back
  290. X        gain = int(255.0*p.outputgain.val)
  291. X        a.val = 1.0
  292. X        a.fixact()
  293. X        panel.drawpanel()
  294. X        audio.setoutgain(gain)
  295. X        audio.write(p.sample)
  296. X        audio.setoutgain(0)
  297. X        a.val = 0.0
  298. X        a.fixact()
  299. X    #
  300. X    p.playbackbutton.downfunc = playback
  301. X    #
  302. X    def record(a):
  303. X        p = a.back
  304. X        size = int(10.0 * 8192.0 * p.recordsize.val)
  305. X        a.val = 1.0
  306. X        a.fixact()
  307. X        panel.drawpanel()
  308. X        audio.setoutgain(0)
  309. X        p.sample = audio.read(size)
  310. X        a.val = 0.0
  311. X        a.fixact()
  312. X    #
  313. X    p.recordbutton.downfunc = record
  314. X    #
  315. X    while 1:
  316. X        act = panel.dopanel()
  317. X
  318. Xmain()
  319. EOF
  320. chmod +x 'demo/sgi/gl_panel/apanel/apanel.py'
  321. fi
  322. if test -s 'demo/sgi/gl_panel/flying/material.py'
  323. then echo '*** I will not over-write existing file demo/sgi/gl_panel/flying/material.py'
  324. else
  325. echo 'x - demo/sgi/gl_panel/flying/material.py'
  326. sed 's/^X//' > 'demo/sgi/gl_panel/flying/material.py' << 'EOF'
  327. Ximport light
  328. X
  329. Xdef mkmatdict () :
  330. X    m = {}
  331. X    m['material 1'] = light.m1
  332. X    m['material 2'] = light.m2
  333. X    m['material 3'] = light.m3
  334. X    m['material 4'] = light.m4
  335. X    m['material 5'] = light.m5
  336. X    m['material 6'] = light.m6
  337. X    m['material 7'] = light.m7
  338. X    m['material 8'] = light.m8
  339. X    m['material 9'] = light.m9
  340. X    #
  341. X    return m
  342. X
  343. Xmaterdict = mkmatdict ()
  344. X
  345. Xdef mklichtdict () :
  346. X    m = {}
  347. X    m['light 1'] = light.light1
  348. X    m['light 2'] = light.light2
  349. X    #
  350. X    return m
  351. X
  352. Xlichtdict = mklichtdict ()
  353. EOF
  354. fi
  355. if test -s 'demo/sgi/gl_panel/flying/objdict.py'
  356. then echo '*** I will not over-write existing file demo/sgi/gl_panel/flying/objdict.py'
  357. else
  358. echo 'x - demo/sgi/gl_panel/flying/objdict.py'
  359. sed 's/^X//' > 'demo/sgi/gl_panel/flying/objdict.py' << 'EOF'
  360. X
  361. Xfrom data import *
  362. X
  363. X#
  364. X#the color light-blue
  365. X#
  366. XLightBlue = lightblue
  367. X
  368. X# the 'object' dictionary contains the strings of the menu items
  369. X# that denote the objects
  370. Xobjects = {}
  371. X
  372. X# object dictionary initialization
  373. Xobjects['sphere'] = [ZERO, o1]
  374. Xobjects['cylinder'] = [ZERO, o2]
  375. Xobjects['cube'] = [ONE, o3]
  376. Xobjects['icecream'] = [ZERO, o4]
  377. Xobjects['disk'] = [ZERO, o5]
  378. Xobjects['diamond'] = [ZERO, o6]
  379. X#objects['glass'] = [ZERO]
  380. Xobjects['pyramid'] = [ZERO, o7]
  381. Xobjects['table'] = [ZERO, o8]
  382. X
  383. X# 'putDict' sets the value of entry 'key' of dictionary 'dict'
  384. Xdef putDict(dict, key, val) :
  385. X    dict[key][0] = val
  386. X
  387. X#
  388. X# 'getDict' get the contents of entry i of key  'key'
  389. X# of dictionary 'dict'
  390. X#
  391. Xdef getDict(dict, key, i) :
  392. X    return dict[key][i]
  393. X
  394. X# the 'options' dictionary contains the strings of the menu items
  395. X# that denote the options
  396. Xoptions = {}
  397. X
  398. X# option dictionary initialization
  399. Xoptions['wire'] = [ZERO]
  400. Xoptions['filled'] = [ONE]
  401. EOF
  402. fi
  403. if test -s 'demo/sgi/gl_panel/twoview/topview.s'
  404. then echo '*** I will not over-write existing file demo/sgi/gl_panel/twoview/topview.s'
  405. else
  406. echo 'x - demo/sgi/gl_panel/twoview/topview.s'
  407. sed 's/^X//' > 'demo/sgi/gl_panel/twoview/topview.s' << 'EOF'
  408. X;;; This file was automatically generated by the panel editor.
  409. X;;; If you read it into gnu emacs, it will automagically format itself.
  410. X
  411. X(panel (prop help creator:user-panel-help)
  412. X(prop user-panel #t)
  413. X(label "Top View Control")
  414. X(x 1020)
  415. X(y 287)
  416. X(al (pnl_hslider (name "xpos")
  417. X(prop help creator:user-act-help)
  418. X(label "X")
  419. X(x 2)
  420. X(y 0.5)
  421. X(w 3.85)
  422. X(h 0.4)
  423. X(val 0.5)
  424. X(downfunc move-then-resize)
  425. X)
  426. X(pnl_vslider (name "zpos")
  427. X(prop help creator:user-act-help)
  428. X(label "Z")
  429. X(x 1.25)
  430. X(y 1.3)
  431. X(w 0.4)
  432. X(h 3.6)
  433. X(val 0.5)
  434. X(downfunc move-then-resize)
  435. X)
  436. X(pnl_dial (name "direction")
  437. X(prop help creator:user-act-help)
  438. X(label "looking direction")
  439. X(x 2.15)
  440. X(y 1.4)
  441. X(w 3.5)
  442. X(h 3.45)
  443. X(val 0.5)
  444. X(downfunc move-then-resize)
  445. X)
  446. X)
  447. X)
  448. X;;; Local Variables:
  449. X;;; mode: scheme
  450. X;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3))
  451. X;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")"))
  452. X;;; eval: (indent-region (point-min) (point-max) nil)
  453. X;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer))
  454. X;;; End:
  455. EOF
  456. fi
  457. if test -s 'doc/README'
  458. then echo '*** I will not over-write existing file doc/README'
  459. else
  460. echo 'x - doc/README'
  461. sed 's/^X//' > 'doc/README' << 'EOF'
  462. XThis directory contains the LaTeX source to the Python documentation.
  463. XThe documentation is not all finished, but good enough to get you
  464. Xstarted.
  465. X
  466. XThe following are the important latex source files:
  467. X
  468. X    tut.tex        A tutorial
  469. X    mod.tex        The library reference
  470. X
  471. XThey both read the style option file "myformat.sty".
  472. X
  473. XYou can use the Makefile to format, preview and print the documents.
  474. XType "make tut" or "make mod" to preview either document with xdvi.
  475. XType "make print" to print them both (this only works if your print
  476. Xspooler is set up just like mine...), or "make all" to create postscript
  477. Xfiles that you can you can print using your local printing commands.
  478. XType "make clean" to get rid of all the intermediate files produced by
  479. Xthe latex process, and other junk files.
  480. X
  481. XYou can just as well ignore the Makefile; all you really need is:
  482. X    latex tut
  483. X    latex tut
  484. X    dvips tut | lpr
  485. Xand similar for the "mod" document.
  486. EOF
  487. fi
  488. if test -s 'doc/SetClass.py'
  489. then echo '*** I will not over-write existing file doc/SetClass.py'
  490. else
  491. echo 'x - doc/SetClass.py'
  492. sed 's/^X//' > 'doc/SetClass.py' << 'EOF'
  493. Xclass Set():
  494. X    def new(self):
  495. X        self.elements = []
  496. X        return self
  497. X    def add(self, e):
  498. X        if e not in self.elements:
  499. X            self.elements.append(e)
  500. X    def remove(self, e):
  501. X        if e in self.elements:
  502. X            for i in range(len(self.elements)):
  503. X                if self.elements[i] = e:
  504. X                    del self.elements[i]
  505. X                    break
  506. X    def is_element(self, e):
  507. X        return e in self.elements
  508. X    def size(self):
  509. X        return len(self.elements)
  510. EOF
  511. fi
  512. if test -s 'doc/fibo.py'
  513. then echo '*** I will not over-write existing file doc/fibo.py'
  514. else
  515. echo 'x - doc/fibo.py'
  516. sed 's/^X//' > 'doc/fibo.py' << 'EOF'
  517. X# Fibonacci numbers demo
  518. X
  519. Xdef fib(n):    # write Fibonacci series up to n
  520. X    a, b = 0, 1
  521. X    while b <= n:
  522. X          print b,
  523. X          a, b = b, a+b
  524. X
  525. Xdef fib2(n): # return Fibonacci series up to n
  526. X    ret = []
  527. X    a, b = 0, 1
  528. X    while b <= n:
  529. X          ret.append(b)
  530. X          a, b = b, a+b
  531. X    return ret
  532. EOF
  533. fi
  534. if test -s 'doc/mod.tex'
  535. then echo '*** I will not over-write existing file doc/mod.tex'
  536. else
  537. echo 'x - doc/mod.tex'
  538. sed 's/^X//' > 'doc/mod.tex' << 'EOF'
  539. X% Format this file with latex.
  540. X
  541. X%\documentstyle[garamond,11pt,myformat]{article}
  542. X\documentstyle[11pt,myformat]{article}
  543. X
  544. X% A command to force the text after an item to start on a new line
  545. X\newcommand{\itembreak}{
  546. X    \mbox{}\\*[0mm]
  547. X}
  548. X
  549. X% A command to define a function item
  550. X\newcommand{\funcitem}[2]{\item[#1(#2)]}
  551. X
  552. X% A command to define an exception item
  553. X\newcommand{\excitem}[2]{
  554. X\item[#1 = {\tt '#2'}]
  555. X\itembreak
  556. X}
  557. X
  558. X\title{\bf
  559. X    Python Library Reference \\
  560. X    (DRAFT)
  561. X}
  562. X
  563. X\author{
  564. X    Guido van Rossum \\
  565. X    Dept. CST, CWI, Kruislaan 413 \\
  566. X    1098 SJ Amsterdam, The Netherlands \\
  567. X    E-mail: {\tt guido@cwi.nl}
  568. X}
  569. X
  570. X\begin{document}
  571. X
  572. X\pagenumbering{roman}
  573. X
  574. X\maketitle
  575. X
  576. X\begin{abstract}
  577. X
  578. X\noindent
  579. XThis document describes the built-in types, exceptions and functions and
  580. Xthe standard modules that come with the {\Python} system.
  581. XIt assumes basic knowledge about the {\Python} language.
  582. XFor an informal introduction to the language, see the Tutorial document.
  583. XThe Language Reference document (XXX not yet existing)
  584. Xgives a more formal reference to the language.
  585. X
  586. X\end{abstract}
  587. X
  588. X\pagebreak
  589. X
  590. X\tableofcontents
  591. X
  592. X\pagebreak
  593. X
  594. X\pagenumbering{arabic}
  595. X
  596. X\input{mod1.tex}
  597. X\input{mod2.tex}
  598. X\input{mod3.tex}
  599. X
  600. X\end{document}
  601. EOF
  602. fi
  603. if test -s 'doc/myformat.sty'
  604. then echo '*** I will not over-write existing file doc/myformat.sty'
  605. else
  606. echo 'x - doc/myformat.sty'
  607. sed 's/^X//' > 'doc/myformat.sty' << 'EOF'
  608. X% Style parameters and macros used by all documents here
  609. X
  610. X% Page lay-out parameters
  611. X\textwidth =      160mm
  612. X\textheight =     240mm
  613. X\topmargin =      -11mm
  614. X\oddsidemargin =    0mm
  615. X\evensidemargin =   0mm
  616. X%\parindent =        0mm
  617. X
  618. X% Frequently used system names
  619. X\newcommand{\Python}{Python}    % Sometimes I want this italicized
  620. X\newcommand{\UNIX}{U{\sc nix}}
  621. X
  622. X% Variable used by begin code command
  623. X\newlength{\codewidth}
  624. X
  625. X\newcommand{\bcode}{
  626. X    % Calculate the text width for the minipage:
  627. X    \setlength{\codewidth}{\linewidth}
  628. X    \addtolength{\codewidth}{-\parindent}
  629. X    %
  630. X    \vspace{3mm}
  631. X    \par
  632. X    \indent
  633. X    \begin{minipage}[t]{\codewidth}
  634. X}
  635. X
  636. X\newcommand{\ecode}{
  637. X    \end{minipage}
  638. X    \vspace{3mm}
  639. X    \par
  640. X    \noindent
  641. X}
  642. EOF
  643. fi
  644. if test -s 'doc/pytry'
  645. then echo '*** I will not over-write existing file doc/pytry'
  646. else
  647. echo 'x - doc/pytry'
  648. sed 's/^X//' > 'doc/pytry' << 'EOF'
  649. XTMP=/usr/tmp/pytry$$
  650. Xtrap 'rm -f $TMP; exit 1' 1 2 3 13 14 15
  651. X
  652. Xcat $* >$TMP
  653. X
  654. X(
  655. X    cat $TMP
  656. X    
  657. X    sed '
  658. X    s/^>>> //
  659. X    s/^>>>$//
  660. X    s/^\.\.\. //
  661. X    s/^\.\.\.$//
  662. X    ' $TMP |
  663. X    python
  664. X    
  665. X    echo '>>> '
  666. X) 2>&1
  667. X
  668. Xrm $TMP
  669. EOF
  670. chmod +x 'doc/pytry'
  671. fi
  672. if test -s 'lib/Histogram.py'
  673. then echo '*** I will not over-write existing file lib/Histogram.py'
  674. else
  675. echo 'x - lib/Histogram.py'
  676. sed 's/^X//' > 'lib/Histogram.py' << 'EOF'
  677. X# Module 'Histogram'
  678. X
  679. Xfrom Buttons import *
  680. X
  681. X# A Histogram displays a histogram of numeric data.
  682. X#
  683. Xclass HistogramAppearance() = LabelAppearance(), Define():
  684. X    #
  685. X    def define(self, parent):
  686. X        Define.define(self, (parent, ''))
  687. X        self.ydata = []
  688. X        self.scale = (0, 100)
  689. X        return self
  690. X    #
  691. X    def setdata(self, (ydata, scale)):
  692. X        self.ydata = ydata
  693. X        self.scale = scale # (min, max)
  694. X        self.parent.change(self.bounds)
  695. X    #
  696. X    def drawpict(self, d):
  697. X        (left, top), (right, bottom) = self.bounds
  698. X        min, max = self.scale
  699. X        size = max-min
  700. X        width, height = right-left, bottom-top
  701. X        ydata = self.ydata
  702. X        npoints = len(ydata)
  703. X        v1 = top + height    # constant
  704. X        h1 = left        # changed in loop
  705. X        for i in range(npoints):
  706. X            h0 = h1
  707. X            v0 = top + height - (ydata[i]-min)*height/size
  708. X            h1 = left + (i+1) * width/npoints
  709. X            d.paint((h0, v0), (h1, v1))
  710. X    #
  711. X
  712. Xclass Histogram() = NoReactivity(), HistogramAppearance(): pass
  713. EOF
  714. fi
  715. if test -s 'lib/Soundogram.py'
  716. then echo '*** I will not over-write existing file lib/Soundogram.py'
  717. else
  718. echo 'x - lib/Soundogram.py'
  719. sed 's/^X//' > 'lib/Soundogram.py' << 'EOF'
  720. X# Module 'Soundogram'
  721. X
  722. Ximport audio
  723. Xfrom Histogram import Histogram
  724. X
  725. Xclass Soundogram() = Histogram():
  726. X    #
  727. X    def define(self, (win, chunk)):
  728. X        width, height = corner = win.getwinsize()
  729. X        bounds = (0, 0), corner
  730. X        self.chunk = chunk
  731. X        self.step = (len(chunk)-1)/(width/2+1) + 1
  732. X        ydata = _make_ydata(chunk, self.step)
  733. X        return Histogram.define(self, (win, bounds, ydata, (0, 128)))
  734. X    #
  735. X    def setchunk(self, chunk):
  736. X        self.chunk = chunk
  737. X        self.recompute()
  738. X    #
  739. X    def recompute(self):
  740. X        (left, top), (right, bottom) = self.bounds
  741. X        width = right - left
  742. X        self.step = (len(chunk)-1)/width + 1
  743. X        ydata = _make_ydata(chunk, self.step)
  744. X        self.setdata(ydata, (0, 128))
  745. X    #
  746. X
  747. X
  748. Xdef _make_ydata(chunk, step):
  749. X    ydata = []
  750. X    for i in range(0, len(chunk), step):
  751. X        piece = audio.chr2num(chunk[i:i+step])
  752. X        mi, ma = min(piece), max(piece)
  753. X        y = max(abs(mi), abs(ma))
  754. X        ydata.append(y)
  755. X    return ydata
  756. EOF
  757. fi
  758. if test -s 'lib/TestCSplit.py'
  759. then echo '*** I will not over-write existing file lib/TestCSplit.py'
  760. else
  761. echo 'x - lib/TestCSplit.py'
  762. sed 's/^X//' > 'lib/TestCSplit.py' << 'EOF'
  763. X# TestCSplit
  764. X
  765. Ximport stdwin
  766. Xfrom stdwinevents import WE_CLOSE
  767. Xfrom WindowParent import WindowParent
  768. Xfrom Buttons import PushButton
  769. X
  770. Xdef main(n):
  771. X    from CSplit import CSplit
  772. X    
  773. X    the_window = WindowParent().create('TestCSplit', (0, 0))
  774. X    the_csplit = CSplit().create(the_window)
  775. X    
  776. X    for i in range(n):
  777. X        the_child = PushButton().define(the_csplit)
  778. X        the_child.settext(`(i+n-1)%n+1`)
  779. X    
  780. X    the_window.realize()
  781. X    
  782. X    while 1:
  783. X        the_event = stdwin.getevent()
  784. X        if the_event[0] = WE_CLOSE: break
  785. X        the_window.dispatch(the_event)
  786. X    the_window.destroy()
  787. X
  788. Xmain(12)
  789. EOF
  790. fi
  791. if test -s 'lib/VUMeter.py'
  792. then echo '*** I will not over-write existing file lib/VUMeter.py'
  793. else
  794. echo 'x - lib/VUMeter.py'
  795. sed 's/^X//' > 'lib/VUMeter.py' << 'EOF'
  796. X# Module 'VUMeter'
  797. X
  798. Ximport audio
  799. Xfrom StripChart import StripChart
  800. X
  801. XK = 1024
  802. XRates = [0, 32*K, 16*K, 8*K]
  803. X
  804. Xclass VUMeter() = StripChart():
  805. X    #
  806. X    # Override define() and timer() methods
  807. X    #
  808. X    def define(self, parent):
  809. X        self = StripChart.define(self, (parent, 128))
  810. X        self.parent.need_timer(self)
  811. X        self.sampling = 0
  812. X        self.rate = 3
  813. X        self.enable(0)
  814. X        return self
  815. X    #
  816. X    def timer(self):
  817. X        if self.sampling:
  818. X            chunk = audio.wait_recording()
  819. X            self.sampling = 0
  820. X            nums = audio.chr2num(chunk)
  821. X            ampl = max(abs(min(nums)), abs(max(nums)))
  822. X            self.append(ampl)
  823. X        if self.enabled and not self.sampling:
  824. X            audio.setrate(self.rate)
  825. X            size = Rates[self.rate]/10
  826. X            size = size/48*48
  827. X            audio.start_recording(size)
  828. X            self.sampling = 1
  829. X        if self.sampling:
  830. X            self.parent.settimer(1)
  831. X    #
  832. X    # New methods: start() and stop()
  833. X    #
  834. X    def stop(self):
  835. X        if self.sampling:
  836. X            chunk = audio.stop_recording()
  837. X            self.sampling = 0
  838. X        self.enable(0)
  839. X    #
  840. X    def start(self):
  841. X        self.enable(1)
  842. X        self.timer()
  843. EOF
  844. fi
  845. if test -s 'lib/anywin.py'
  846. then echo '*** I will not over-write existing file lib/anywin.py'
  847. else
  848. echo 'x - lib/anywin.py'
  849. sed 's/^X//' > 'lib/anywin.py' << 'EOF'
  850. X# Module 'anywin'
  851. X# Open a file or directory in a window
  852. X
  853. Ximport dirwin
  854. Ximport filewin
  855. Ximport path
  856. X
  857. Xdef open(name):
  858. X    print 'opening', name, '...'
  859. X    if path.isdir(name):
  860. X        w = dirwin.open(name)
  861. X    else:
  862. X        w = filewin.open(name)
  863. X    return w
  864. EOF
  865. fi
  866. if test -s 'lib/dircache.py'
  867. then echo '*** I will not over-write existing file lib/dircache.py'
  868. else
  869. echo 'x - lib/dircache.py'
  870. sed 's/^X//' > 'lib/dircache.py' << 'EOF'
  871. X# Module 'dircache'
  872. X#
  873. X# Return a sorted list of the files in a POSIX directory, using a cache
  874. X# to avoid reading the directory more often than necessary.
  875. X# Also contains a subroutine to append slashes to directories.
  876. X
  877. Ximport posix
  878. Ximport path
  879. X
  880. Xcache = {}
  881. X
  882. Xdef listdir(path): # List directory contents, using cache
  883. X    try:
  884. X        cached_mtime, list = cache[path]
  885. X        del cache[path]
  886. X    except RuntimeError:
  887. X        cached_mtime, list = -1, []
  888. X    try:
  889. X        mtime = posix.stat(path)[8]
  890. X    except posix.error:
  891. X        return []
  892. X    if mtime <> cached_mtime:
  893. X        try:
  894. X            list = posix.listdir(path)
  895. X        except posix.error:
  896. X            return []
  897. X        list.sort()
  898. X    cache[path] = mtime, list
  899. X    return list
  900. X
  901. Xopendir = listdir # XXX backward compatibility
  902. X
  903. Xdef annotate(head, list): # Add '/' suffixes to directories
  904. X    for i in range(len(list)):
  905. X        if path.isdir(path.cat(head, list[i])):
  906. X            list[i] = list[i] + '/'
  907. EOF
  908. fi
  909. if test -s 'lib/dirwin.py'
  910. then echo '*** I will not over-write existing file lib/dirwin.py'
  911. else
  912. echo 'x - lib/dirwin.py'
  913. sed 's/^X//' > 'lib/dirwin.py' << 'EOF'
  914. X# Module 'dirwin'
  915. X
  916. X# Directory windows, a subclass of listwin
  917. X
  918. Ximport gwin
  919. Ximport listwin
  920. Ximport anywin
  921. Ximport path
  922. Ximport dircache
  923. X
  924. Xdef action(w, string, i, detail):
  925. X    (h, v), clicks, button, mask = detail
  926. X    if clicks = 2:
  927. X        name = path.cat(w.name, string)
  928. X        try:
  929. X            w2 = anywin.open(name)
  930. X            w2.parent = w
  931. X        except posix.error, why:
  932. X            stdwin.message('Can\'t open ' + name + ': ' + why[1])
  933. X
  934. Xdef open(name):
  935. X    name = path.cat(name, '')
  936. X    list = dircache.opendir(name)[:]
  937. X    list.sort()
  938. X    dircache.annotate(name, list)
  939. X    w = listwin.open(name, list)
  940. X    w.name = name
  941. X    w.action = action
  942. X    return w
  943. EOF
  944. fi
  945. if test -s 'lib/fact.py'
  946. then echo '*** I will not over-write existing file lib/fact.py'
  947. else
  948. echo 'x - lib/fact.py'
  949. sed 's/^X//' > 'lib/fact.py' << 'EOF'
  950. X# Factorize numbers -- slow, could use a table of all primes <= 2*16
  951. X
  952. Ximport sys
  953. Ximport math
  954. X
  955. Xerror = 'fact.error'        # exception
  956. X
  957. Xdef fact(n):
  958. X    if n < 1: raise error    # fact() argument should be >= 1
  959. X    if n = 1: return []    # special case
  960. X    res = []
  961. X    _fact(n, 2, res)
  962. X    return res
  963. X
  964. Xdef _fact(n, lowest, res):
  965. X    highest = int(math.sqrt(float(n+1)))
  966. X    for i in range(lowest, highest+1):
  967. X        if n%i = 0:
  968. X            res.append(i)
  969. X            _fact(n/i, i, res)
  970. X            break
  971. X    else:
  972. X        res.append(n)
  973. X
  974. Xdef main():
  975. X    if len(sys.argv) > 1:
  976. X        for arg in sys.argv[1:]:
  977. X            n = eval(arg)
  978. X            print n, fact(n)
  979. X    else:
  980. X        try:
  981. X            while 1:
  982. X                print fact(input())
  983. X        except EOFError:
  984. X            pass
  985. X
  986. Xmain()
  987. EOF
  988. fi
  989. if test -s 'lib/filewin.py'
  990. then echo '*** I will not over-write existing file lib/filewin.py'
  991. else
  992. echo 'x - lib/filewin.py'
  993. sed 's/^X//' > 'lib/filewin.py' << 'EOF'
  994. X# Module 'filewin'
  995. X# File windows, a subclass of textwin (which is a subclass of gwin)
  996. X
  997. Ximport textwin
  998. Xfrom util import readfile
  999. X
  1000. X
  1001. X# FILE WINDOW
  1002. X
  1003. Xdef open_readonly(fn): # Open a file window
  1004. X    w = textwin.open_readonly(fn, readfile(fn))
  1005. X    w.fn = fn
  1006. X    return w
  1007. X
  1008. Xdef open(fn): # Open a file window
  1009. X    w = textwin.open(fn, readfile(fn))
  1010. X    w.fn = fn
  1011. X    return w
  1012. EOF
  1013. fi
  1014. if test -s 'lib/fnmatch.py'
  1015. then echo '*** I will not over-write existing file lib/fnmatch.py'
  1016. else
  1017. echo 'x - lib/fnmatch.py'
  1018. sed 's/^X//' > 'lib/fnmatch.py' << 'EOF'
  1019. X# module 'fnmatch' -- filename matching with shell patterns
  1020. X
  1021. X# XXX [] patterns are not supported (but recognized)
  1022. X
  1023. Xdef fnmatch(name, pat):
  1024. X    if '*' in pat or '?' in pat or '[' in pat:
  1025. X        return fnmatch1(name, pat)
  1026. X    return name = pat
  1027. X
  1028. Xdef fnmatch1(name, pat):
  1029. X    for i in range(len(pat)):
  1030. X        c = pat[i]
  1031. X        if c = '*':
  1032. X            restpat = pat[i+1:]
  1033. X            if '*' in restpat or '?' in restpat or '[' in restpat:
  1034. X                for i in range(i, len(name)):
  1035. X                    if fnmatch1(name[i:], restpat):
  1036. X                        return 1
  1037. X                return 0
  1038. X            else:
  1039. X                return name[len(name)-len(restpat):] = restpat
  1040. X        elif c = '?':
  1041. X            if len(name) <= i : return 0
  1042. X        elif c = '[':
  1043. X            return 0 # XXX
  1044. X        else:
  1045. X            if name[i:i+1] <> c:
  1046. X                return 0
  1047. X    return 1
  1048. X
  1049. Xdef fnmatchlist(names, pat):
  1050. X    res = []
  1051. X    for name in names:
  1052. X        if fnmatch(name, pat): res.append(name)
  1053. X    return res
  1054. EOF
  1055. fi
  1056. if test -s 'lib/glob.py'
  1057. then echo '*** I will not over-write existing file lib/glob.py'
  1058. else
  1059. echo 'x - lib/glob.py'
  1060. sed 's/^X//' > 'lib/glob.py' << 'EOF'
  1061. X# Module 'glob' -- filename globbing.
  1062. X
  1063. Ximport posix
  1064. Ximport path
  1065. Ximport fnmatch
  1066. X
  1067. Xdef glob(pathname):
  1068. X    if not has_magic(pathname): return [pathname]
  1069. X    dirname, basename = path.split(pathname)
  1070. X    if dirname[-1:] = '/' and dirname <> '/':
  1071. X        dirname = dirname[:-1]
  1072. X    if has_magic(dirname):
  1073. X        list = glob(dirname)
  1074. X    else:
  1075. X        list = [dirname]
  1076. X    if not has_magic(basename):
  1077. X        result = []
  1078. X        for dirname in list:
  1079. X            if basename or path.isdir(dirname):
  1080. X                name = path.cat(dirname, basename)
  1081. X                if path.exists(name):
  1082. X                    result.append(name)
  1083. X    else:
  1084. X        result = []
  1085. X        for dirname in list:
  1086. X            sublist = glob1(dirname, basename)
  1087. X            for name in sublist:
  1088. X                result.append(path.cat(dirname, name))
  1089. X    return result
  1090. X
  1091. Xdef glob1(dirname, pattern):
  1092. X    if not dirname: dirname = '.'
  1093. X    try:
  1094. X        names = posix.listdir(dirname)
  1095. X    except posix.error:
  1096. X        return []
  1097. X    result = []
  1098. X    for name in names:
  1099. X        if name[0] <> '.' or pattern[0] = '.':
  1100. X            if fnmatch.fnmatch(name, pattern): result.append(name)
  1101. X    return result
  1102. X
  1103. Xdef has_magic(s):
  1104. X    return '*' in s or '?' in s or '[' in s
  1105. EOF
  1106. fi
  1107. if test -s 'lib/grep.py'
  1108. then echo '*** I will not over-write existing file lib/grep.py'
  1109. else
  1110. echo 'x - lib/grep.py'
  1111. sed 's/^X//' > 'lib/grep.py' << 'EOF'
  1112. X# 'grep'
  1113. X
  1114. Ximport regexp
  1115. Ximport string
  1116. X
  1117. Xdef grep(expr, filename):
  1118. X    prog = regexp.compile(expr)
  1119. X    fp = open(filename, 'r')
  1120. X    lineno = 0
  1121. X    while 1:
  1122. X        line = fp.readline()
  1123. X        if not line: break
  1124. X        lineno = lineno + 1
  1125. X        res = prog.exec(line)
  1126. X        if res:
  1127. X            #print res
  1128. X            start, end = res[0]
  1129. X            if line[-1:] = '\n': line = line[:-1]
  1130. X            prefix = string.rjust(`lineno`, 3) + ': '
  1131. X            print prefix + line
  1132. X            if 0:
  1133. X                line = line[:start]
  1134. X                if '\t' not in line:
  1135. X                    prefix = ' ' * (len(prefix) + start)
  1136. X                else:
  1137. X                    prefix = ' ' * len(prefix)
  1138. X                    for c in line:
  1139. X                        if c <> '\t': c = ' '
  1140. X                        prefix = prefix + c
  1141. X                if start = end: prefix = prefix + '\\'
  1142. X                else: prefix = prefix + '^'*(end-start)
  1143. X                print prefix
  1144. EOF
  1145. fi
  1146. if test -s 'lib/maccache.py'
  1147. then echo '*** I will not over-write existing file lib/maccache.py'
  1148. else
  1149. echo 'x - lib/maccache.py'
  1150. sed 's/^X//' > 'lib/maccache.py' << 'EOF'
  1151. X# Module 'maccache'
  1152. X#
  1153. X# Maintain a cache of listdir(), isdir(), isfile() or exists() outcomes.
  1154. X
  1155. Ximport mac
  1156. Ximport macpath
  1157. X
  1158. X
  1159. X# The cache.
  1160. X# Keys are absolute pathnames;
  1161. X# values are 0 (nothing), 1 (file) or [...] (dir).
  1162. X#
  1163. Xcache = {}
  1164. X
  1165. X
  1166. X# Current working directory.
  1167. X#
  1168. Xcwd = mac.getcwd()
  1169. X
  1170. X
  1171. X# Constants.
  1172. X#
  1173. XNONE = 0
  1174. XFILE = 1
  1175. XLISTTYPE = type([])
  1176. X
  1177. Xdef _stat(name):
  1178. X    name = macpath.cat(cwd, name)
  1179. X    if cache.has_key(name):
  1180. X        return cache[name]
  1181. X    if macpath.isfile(name):
  1182. X        cache[name] = FILE
  1183. X        return FILE
  1184. X    try:
  1185. X        list = mac.listdir(name)
  1186. X    except:
  1187. X        cache[name] = NONE
  1188. X        return NONE
  1189. X    cache[name] = list
  1190. X    if name[-1:] = ':': cache[name[:-1]] = list
  1191. X    else: cache[name+':'] = list
  1192. X    return list
  1193. X
  1194. Xdef isdir(name):
  1195. X    st = _stat(name)
  1196. X    return type(st) = LISTTYPE
  1197. X
  1198. Xdef isfile(name):
  1199. X    st = _stat(name)
  1200. X    return st = FILE
  1201. X
  1202. Xdef exists(name):
  1203. X    st = _stat(name)
  1204. X    return st <> NONE
  1205. X
  1206. Xdef listdir(name):
  1207. X    st = _stat(name)
  1208. X    if type(st) = LISTTYPE:
  1209. X        return st
  1210. X    else:
  1211. X        raise RuntimeError, 'list non-directory'
  1212. EOF
  1213. fi
  1214. if test -s 'lib/macglob.py'
  1215. then echo '*** I will not over-write existing file lib/macglob.py'
  1216. else
  1217. echo 'x - lib/macglob.py'
  1218. sed 's/^X//' > 'lib/macglob.py' << 'EOF'
  1219. X# Module 'macglob' -- version of 'glob' for the Macintosh.
  1220. X
  1221. X# XXX At least one bug is left: a pattern like '*:' is treated
  1222. X# XXX as a relative pathname (and returns as if it was ':*:').
  1223. X
  1224. Ximport mac
  1225. Ximport macpath
  1226. Ximport fnmatch
  1227. X
  1228. Xdef glob(pathname):
  1229. X    if not has_magic(pathname): return [pathname]
  1230. X    dirname, basename = macpath.split(pathname)
  1231. X    if has_magic(dirname):
  1232. X        if dirname[-1:] = ':': dirname = dirname[:-1]
  1233. X        list = glob(dirname)
  1234. X    else:
  1235. X        list = [dirname]
  1236. X    if not has_magic(basename):
  1237. X        result = []
  1238. X        for dirname in list:
  1239. X            if basename or macpath.isdir(dirname):
  1240. X                name = macpath.cat(dirname, basename)
  1241. X                if macpath.exists(name):
  1242. X                    result.append(name)
  1243. X    else:
  1244. X        result = []
  1245. X        for dirname in list:
  1246. X            sublist = glob1(dirname, basename)
  1247. X            for name in sublist:
  1248. X                result.append(macpath.cat(dirname, name))
  1249. X    return result
  1250. X
  1251. Xdef glob1(dirname, pattern):
  1252. X    if not dirname: dirname = ':'
  1253. X    try:
  1254. X        names = mac.listdir(dirname)
  1255. X    except mac.error:
  1256. X        return []
  1257. X    result = []
  1258. X    for name in names:
  1259. X        if name[0] <> '.' or pattern[0] = '.':
  1260. X            if fnmatch.fnmatch(name, pattern): result.append(name)
  1261. X    return result
  1262. X
  1263. Xdef has_magic(s):
  1264. X    return '*' in s or '?' in s or '[' in s
  1265. EOF
  1266. fi
  1267. if test -s 'lib/minmax.py'
  1268. then echo '*** I will not over-write existing file lib/minmax.py'
  1269. else
  1270. echo 'x - lib/minmax.py'
  1271. sed 's/^X//' > 'lib/minmax.py' << 'EOF'
  1272. X# Module 'minmax'
  1273. X# These are now built in functions.
  1274. X# For compatibility, we export the builtins
  1275. X
  1276. Xmin = min
  1277. Xmax = max
  1278. EOF
  1279. fi
  1280. if test -s 'lib/packmail.py'
  1281. then echo '*** I will not over-write existing file lib/packmail.py'
  1282. else
  1283. echo 'x - lib/packmail.py'
  1284. sed 's/^X//' > 'lib/packmail.py' << 'EOF'
  1285. X# Module 'packmail' -- create a shell script out of some files.
  1286. X
  1287. Ximport mac
  1288. Ximport macpath
  1289. Xfrom stat import ST_MTIME
  1290. X
  1291. X# Pack one file
  1292. Xdef pack(outfp, file, name):
  1293. X    fp = open(file, 'r')
  1294. X    outfp.write('sed "s/^X//" >' + name + ' <<"!"\n')
  1295. X    while 1:
  1296. X        line = fp.readline()
  1297. X        if not line: break
  1298. X        if line[-1:] <> '\n':
  1299. X            line = line + '\n'
  1300. X        outfp.write('X' + line)
  1301. X    outfp.write('!\n')
  1302. X
  1303. X# Pack some files from a directory
  1304. Xdef packsome(outfp, dirname, names):
  1305. X    for name in names:
  1306. X        print name
  1307. X        file = macpath.cat(dirname, name)
  1308. X        pack(outfp, file, name)
  1309. X
  1310. X# Pack all files from a directory
  1311. Xdef packall(outfp, dirname):
  1312. X    names = mac.listdir(dirname)
  1313. X    names.sort()
  1314. X    packsome(outfp, dirname, names)
  1315. X
  1316. X# Pack all files from a directory that are not older than a give one
  1317. Xdef packnotolder(outfp, dirname, oldest):
  1318. X    names = mac.listdir(dirname)
  1319. X    oldest = macpath.cat(dirname, oldest)
  1320. X    st = mac.stat(oldest)
  1321. X    mtime = st[ST_MTIME]
  1322. X    todo = []
  1323. X    for name in names:
  1324. X        print name, '...',
  1325. X        st = mac.stat(macpath.cat(dirname, name))
  1326. X        if st[ST_MTIME] >= mtime:
  1327. X            print 'Yes.'
  1328. X            todo.append(name)
  1329. X        else:
  1330. X            print 'No.'
  1331. X    todo.sort()
  1332. X    packsome(outfp, dirname, todo)
  1333. EOF
  1334. fi
  1335. if test -s 'lib/rand.py'
  1336. then echo '*** I will not over-write existing file lib/rand.py'
  1337. else
  1338. echo 'x - lib/rand.py'
  1339. sed 's/^X//' > 'lib/rand.py' << 'EOF'
  1340. X# Module 'rand'
  1341. X
  1342. Ximport whrandom
  1343. X
  1344. Xdef srand(seed):
  1345. X    whrandom.seed(seed%256, seed/256%256, seed/65536%256)
  1346. X
  1347. Xdef rand():
  1348. X    return int(whrandom.random() * 32768.0) % 32768
  1349. X
  1350. Xdef choice(seq):
  1351. X    return seq[rand() % len(seq)]
  1352. EOF
  1353. fi
  1354. if test -s 'lib/stat.py'
  1355. then echo '*** I will not over-write existing file lib/stat.py'
  1356. else
  1357. echo 'x - lib/stat.py'
  1358. sed 's/^X//' > 'lib/stat.py' << 'EOF'
  1359. X# Module 'stat'
  1360. X
  1361. X# Defines constants and functions for interpreting stat/lstat struct
  1362. X# as returned by posix.stat() and posix.lstat() (if it exists).
  1363. X
  1364. X# XXX This module may have to be adapted for UNIXoid systems whose
  1365. X# <sys/stat.h> deviates from AT&T or BSD UNIX; their S_IF* constants
  1366. X# may differ.
  1367. X
  1368. X# Suggested usage: from stat import *
  1369. X
  1370. X# Tuple indices for stat struct members
  1371. X
  1372. XST_MODE  = 0
  1373. XST_INO   = 1
  1374. XST_DEV   = 2
  1375. XST_NLINK = 3
  1376. XST_UID   = 4
  1377. XST_GID   = 5
  1378. XST_SIZE  = 6
  1379. XST_ATIME = 7
  1380. XST_MTIME = 8
  1381. XST_CTIME = 9
  1382. X
  1383. Xdef S_IMODE(mode):
  1384. X    return mode%4096
  1385. Xdef S_IFMT(mode):
  1386. X    return mode - mode%4096
  1387. X
  1388. XS_IFDIR  = 0040000
  1389. XS_IFCHR  = 0020000
  1390. XS_IFBLK  = 0060000
  1391. XS_IFREG  = 0100000
  1392. XS_IFIFO  = 0010000
  1393. XS_IFLNK  = 0120000
  1394. XS_IFSOCK = 0140000
  1395. X
  1396. Xdef S_ISDIR(mode):
  1397. X    return S_IFMT(mode) = S_IFDIR
  1398. X
  1399. Xdef S_ISCHR(mode):
  1400. X    return S_IFMT(mode) = S_IFCHR
  1401. X
  1402. Xdef S_ISBLK(mode):
  1403. X    return S_IFMT(mode) = S_IFBLK
  1404. X
  1405. Xdef S_ISREG(mode):
  1406. X    return S_IFMT(mode) = S_IFREG
  1407. X
  1408. Xdef S_ISFIFO(mode):
  1409. X    return S_IFMT(mode) = S_IFIFO
  1410. X
  1411. Xdef S_ISLNK(mode):
  1412. X    return S_IFMT(mode) = S_IFLNK
  1413. X
  1414. Xdef S_ISSOCK(mode):
  1415. X    return S_IFMT(mode) = S_IFSOCK
  1416. EOF
  1417. fi
  1418. if test -s 'lib/stdwinsupport.py'
  1419. then echo '*** I will not over-write existing file lib/stdwinsupport.py'
  1420. else
  1421. echo 'x - lib/stdwinsupport.py'
  1422. sed 's/^X//' > 'lib/stdwinsupport.py' << 'EOF'
  1423. X# Module 'stdwinsupport'
  1424. X
  1425. Ximport stdwin
  1426. X
  1427. Xeventnames =              ['null', 'activate', 'char', 'command']
  1428. Xeventnames = eventnames + ['mouse_down', 'mouse_move', 'mouse_up', 'menu']
  1429. Xeventnames = eventnames + ['size', 'move', 'draw', 'timer', 'deactivate']
  1430. X
  1431. Xwe_null       =  0
  1432. Xwe_activate   =  1
  1433. Xwe_char       =  2
  1434. Xwe_command    =  3
  1435. Xwe_mouse_down =  4
  1436. Xwe_mouse_move =  5
  1437. Xwe_mouse_up   =  6
  1438. Xwe_menu       =  7
  1439. Xwe_size       =  8
  1440. Xwe_move       =  9
  1441. Xwe_draw       = 10
  1442. Xwe_timer      = 11
  1443. Xwe_deactivate = 12
  1444. X
  1445. Xcommandnames = ['?', 'close', 'left', 'right', 'up', 'down', 'cancel']
  1446. Xcommandnames = commandnames + ['backspace', 'tab', 'return']
  1447. X
  1448. Xwc_close     = 1
  1449. Xwc_left      = 2
  1450. Xwc_right     = 3
  1451. Xwc_up        = 4
  1452. Xwc_down      = 5
  1453. Xwc_cancel    = 6    # not reported -- turned into KeyboardInterrupt
  1454. Xwc_backspace = 7
  1455. Xwc_tab       = 8
  1456. Xwc_return    = 9
  1457. EOF
  1458. fi
  1459. if test -s 'lib/util.py'
  1460. then echo '*** I will not over-write existing file lib/util.py'
  1461. else
  1462. echo 'x - lib/util.py'
  1463. sed 's/^X//' > 'lib/util.py' << 'EOF'
  1464. X# Module 'util' -- some useful functions that don't fit elsewhere
  1465. X
  1466. X
  1467. X# Remove an item from a list.
  1468. X# No complaints if it isn't in the list at all.
  1469. X# If it occurs more than once, remove the first occurrence.
  1470. X#
  1471. Xdef remove(item, list):
  1472. X    for i in range(len(list)):
  1473. X        if list[i] = item:
  1474. X            del list[i]
  1475. X            break
  1476. X
  1477. X
  1478. X# Return a string containing a file's contents.
  1479. X#
  1480. Xdef readfile(fn):
  1481. X    return readopenfile(open(fn, 'r'))
  1482. X
  1483. X
  1484. X# Read an open file until EOF.
  1485. X#
  1486. Xdef readopenfile(fp):
  1487. X    BUFSIZE = 512*8
  1488. X    data = ''
  1489. X    while 1:
  1490. X        buf = fp.read(BUFSIZE)
  1491. X        if not buf: break
  1492. X        data = data + buf
  1493. X    return data
  1494. EOF
  1495. fi
  1496. if test -s 'src/To.do'
  1497. then echo '*** I will not over-write existing file src/To.do'
  1498. else
  1499. echo 'x - src/To.do'
  1500. sed 's/^X//' > 'src/To.do' << 'EOF'
  1501. X- return better errors for file objects (also check read/write allowed, etc.)
  1502. X
  1503. X- introduce more specific exceptions (e.g., zero divide, index failure, ...)
  1504. X
  1505. X- why do reads from stdin fail when I suspend the process?
  1506. X
  1507. X- introduce macros to set/inspect errno for syscalls, to support things
  1508. X  like getoserr()
  1509. X
  1510. X- fix interrupt handling (interruptable system calls should call
  1511. X  intrcheck() to clear the interrupt status)
  1512. EOF
  1513. fi
  1514. if test -s 'src/assert.h'
  1515. then echo '*** I will not over-write existing file src/assert.h'
  1516. else
  1517. echo 'x - src/assert.h'
  1518. sed 's/^X//' > 'src/assert.h' << 'EOF'
  1519. X/***********************************************************
  1520. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1521. XNetherlands.
  1522. X
  1523. X                        All Rights Reserved
  1524. X
  1525. XPermission to use, copy, modify, and distribute this software and its 
  1526. Xdocumentation for any purpose and without fee is hereby granted, 
  1527. Xprovided that the above copyright notice appear in all copies and that
  1528. Xboth that copyright notice and this permission notice appear in 
  1529. Xsupporting documentation, and that the names of Stichting Mathematisch
  1530. XCentrum or CWI not be used in advertising or publicity pertaining to
  1531. Xdistribution of the software without specific, written prior permission.
  1532. X
  1533. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1534. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1535. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1536. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1537. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1538. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1539. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1540. X
  1541. X******************************************************************/
  1542. X
  1543. X#define assert(e) { if (!(e)) { printf("Assertion failed\n"); abort(); } }
  1544. EOF
  1545. fi
  1546. if test -s 'src/bltinmodule.h'
  1547. then echo '*** I will not over-write existing file src/bltinmodule.h'
  1548. else
  1549. echo 'x - src/bltinmodule.h'
  1550. sed 's/^X//' > 'src/bltinmodule.h' << 'EOF'
  1551. X/***********************************************************
  1552. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1553. XNetherlands.
  1554. X
  1555. X                        All Rights Reserved
  1556. X
  1557. XPermission to use, copy, modify, and distribute this software and its 
  1558. Xdocumentation for any purpose and without fee is hereby granted, 
  1559. Xprovided that the above copyright notice appear in all copies and that
  1560. Xboth that copyright notice and this permission notice appear in 
  1561. Xsupporting documentation, and that the names of Stichting Mathematisch
  1562. XCentrum or CWI not be used in advertising or publicity pertaining to
  1563. Xdistribution of the software without specific, written prior permission.
  1564. X
  1565. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1566. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1567. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1568. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1569. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1570. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1571. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1572. X
  1573. X******************************************************************/
  1574. X
  1575. X/* Built-in module interface */
  1576. X
  1577. Xextern object *getbuiltin PROTO((char *));
  1578. EOF
  1579. fi
  1580. if test -s 'src/fgetsintr.h'
  1581. then echo '*** I will not over-write existing file src/fgetsintr.h'
  1582. else
  1583. echo 'x - src/fgetsintr.h'
  1584. sed 's/^X//' > 'src/fgetsintr.h' << 'EOF'
  1585. X/***********************************************************
  1586. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1587. XNetherlands.
  1588. X
  1589. X                        All Rights Reserved
  1590. X
  1591. XPermission to use, copy, modify, and distribute this software and its 
  1592. Xdocumentation for any purpose and without fee is hereby granted, 
  1593. Xprovided that the above copyright notice appear in all copies and that
  1594. Xboth that copyright notice and this permission notice appear in 
  1595. Xsupporting documentation, and that the names of Stichting Mathematisch
  1596. XCentrum or CWI not be used in advertising or publicity pertaining to
  1597. Xdistribution of the software without specific, written prior permission.
  1598. X
  1599. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1600. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1601. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1602. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1603. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1604. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1605. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1606. X
  1607. X******************************************************************/
  1608. X
  1609. Xextern int fgets_intr PROTO((char *, int, FILE *));
  1610. EOF
  1611. fi
  1612. if test -s 'src/rltokenizer.c'
  1613. then echo '*** I will not over-write existing file src/rltokenizer.c'
  1614. else
  1615. echo 'x - src/rltokenizer.c'
  1616. sed 's/^X//' > 'src/rltokenizer.c' << 'EOF'
  1617. X/***********************************************************
  1618. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1619. XNetherlands.
  1620. X
  1621. X                        All Rights Reserved
  1622. X
  1623. XPermission to use, copy, modify, and distribute this software and its 
  1624. Xdocumentation for any purpose and without fee is hereby granted, 
  1625. Xprovided that the above copyright notice appear in all copies and that
  1626. Xboth that copyright notice and this permission notice appear in 
  1627. Xsupporting documentation, and that the names of Stichting Mathematisch
  1628. XCentrum or CWI not be used in advertising or publicity pertaining to
  1629. Xdistribution of the software without specific, written prior permission.
  1630. X
  1631. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1632. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1633. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1634. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1635. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1636. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1637. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1638. X
  1639. X******************************************************************/
  1640. X
  1641. X#define USE_READLINE
  1642. X#include "tokenizer.c"
  1643. EOF
  1644. fi
  1645. if test -s 'src/stubcode.h'
  1646. then echo '*** I will not over-write existing file src/stubcode.h'
  1647. else
  1648. echo 'x - src/stubcode.h'
  1649. sed 's/^X//' > 'src/stubcode.h' << 'EOF'
  1650. X/***********************************************************
  1651. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1652. XNetherlands.
  1653. X
  1654. X                        All Rights Reserved
  1655. X
  1656. XPermission to use, copy, modify, and distribute this software and its 
  1657. Xdocumentation for any purpose and without fee is hereby granted, 
  1658. Xprovided that the above copyright notice appear in all copies and that
  1659. Xboth that copyright notice and this permission notice appear in 
  1660. Xsupporting documentation, and that the names of Stichting Mathematisch
  1661. XCentrum or CWI not be used in advertising or publicity pertaining to
  1662. Xdistribution of the software without specific, written prior permission.
  1663. X
  1664. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1665. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1666. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1667. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1668. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1669. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1670. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1671. X
  1672. X******************************************************************/
  1673. X
  1674. X
  1675. X#define CAP    0
  1676. X#define STUBC    1
  1677. X#define NAME    2
  1678. EOF
  1679. fi
  1680. echo 'Part 21 out of 21 of pack.out complete.'
  1681. exit 0
  1682.