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

  1. From: guido@cwi.nl (Guido van Rossum)
  2. Newsgroups: alt.sources
  3. Subject: Python 0.9.1 part 19/21
  4. Message-ID: <2981@charon.cwi.nl>
  5. Date: 19 Feb 91 17:42:49 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 19 out of 21:'
  12. if test -s 'demo/scripts/xxci.py'
  13. then echo '*** I will not over-write existing file demo/scripts/xxci.py'
  14. else
  15. echo 'x - demo/scripts/xxci.py'
  16. sed 's/^X//' > 'demo/scripts/xxci.py' << 'EOF'
  17. X#! /ufs/guido/bin/sgi/python
  18. X
  19. X# xxci
  20. X#
  21. X# check in files for which rcsdiff returns nonzero exit status
  22. X
  23. Ximport sys
  24. Ximport posix
  25. Ximport stat
  26. Ximport path
  27. Ximport commands
  28. X
  29. XMAXSIZE = 200*1024 # Files this big must be binaries and are skipped.
  30. X
  31. Xdef getargs():
  32. X    args = sys.argv[1:]
  33. X    if args:
  34. X        return args
  35. X    print 'No arguments, checking almost *'
  36. X    for file in posix.listdir('.'):
  37. X        if not skipfile(file):
  38. X            args.append(file)
  39. X    if not args:
  40. X        print 'Nothing to do -- exit 1'
  41. X        sys.exit(1)
  42. X    args.sort()
  43. X    return args
  44. X
  45. Xbadnames = ['tags', 'xyzzy']
  46. Xbadprefixes = ['.', ',', '@', '#', 'o.']
  47. Xbadsuffixes = \
  48. X    ['~', '.a', '.o', '.old', '.bak', '.orig', '.new', '.prev', '.not']
  49. X# XXX Should generalize even more to use fnmatch!
  50. X
  51. Xdef skipfile(file):
  52. X    if file in badnames or \
  53. X        badprefix(file) or badsuffix(file) or \
  54. X        path.islink(file) or path.isdir(file):
  55. X        return 1
  56. X    # Skip huge files -- probably binaries.
  57. X    try:
  58. X        st = posix.stat(file)
  59. X    except posix.error:
  60. X        return 1 # Doesn't exist -- skip it
  61. X    return st[stat.ST_SIZE] >= MAXSIZE
  62. X
  63. Xdef badprefix(file):
  64. X    for bad in badprefixes:
  65. X        if file[:len(bad)] = bad: return 1
  66. X    return 0
  67. X
  68. Xdef badsuffix(file):
  69. X    for bad in badsuffixes:
  70. X        if file[-len(bad):] = bad: return 1
  71. X    return 0
  72. X
  73. Xdef go(args):
  74. X    for file in args:
  75. X        print file + ':'
  76. X        if run('rcsdiff -c', file):
  77. X            if askyesno('Check in ' + file + ' ? '):
  78. X                sts = run('rcs -l', file) # ignored
  79. X                # can't use run() here because it's interactive
  80. X                sts = posix.system('ci -l ' + file)
  81. X
  82. Xdef run(cmd, file):
  83. X    sts, output = commands.getstatusoutput(cmd + commands.mkarg(file))
  84. X    if sts:
  85. X        print output
  86. X        print 'Exit status', sts
  87. X    return sts
  88. X
  89. Xdef askyesno(prompt):
  90. X    s = raw_input(prompt)
  91. X    return s in ['y', 'yes']
  92. X
  93. Xgo(getargs())
  94. EOF
  95. chmod +x 'demo/scripts/xxci.py'
  96. fi
  97. if test -s 'demo/sgi/gl_panel/apanel/apanel.s'
  98. then echo '*** I will not over-write existing file demo/sgi/gl_panel/apanel/apanel.s'
  99. else
  100. echo 'x - demo/sgi/gl_panel/apanel/apanel.s'
  101. sed 's/^X//' > 'demo/sgi/gl_panel/apanel/apanel.s' << 'EOF'
  102. X;;; This file was automatically generated by the panel editor.
  103. X;;; If you read it into gnu emacs, it will automagically format itself.
  104. X
  105. X(panel (prop help creator:user-panel-help)
  106. X(prop user-panel #t)
  107. X(label "Audio Control Panel")
  108. X(x 395)
  109. X(y 69)
  110. X(al (pnl_filled_vslider (name "outputgain")
  111. X(prop help creator:user-act-help)
  112. X(label "output gain")
  113. X(x 6.5)
  114. X(y 0.75)
  115. X(w 0.4)
  116. X(h 4.35)
  117. X(val 0.329)
  118. X(labeltype 13)
  119. X(downfunc move-then-resize)
  120. X)
  121. X(pnl_frame (prop help creator:user-frame-help)
  122. X(x 0.25)
  123. X(y 2.75)
  124. X(w 5.1)
  125. X(h 2.3)
  126. X(downfunc move-then-resize)
  127. X(al (pnl_filled_hslider (name "recordsize")
  128. X(prop help creator:user-act-help)
  129. X(label "recording length")
  130. X(x -0.75)
  131. X(w 3.3)
  132. X(h 0.4)
  133. X(val 0.1)
  134. X(labeltype 11)
  135. X(downfunc move-then-resize)
  136. X)
  137. X(pnl_label (prop help creator:user-act-help)
  138. X(label "(max 10 seconds)")
  139. X(x -0.75)
  140. X(y -0.75)
  141. X(downfunc move-then-resize)
  142. X)
  143. X(pnl_wide_button (name "recordbutton")
  144. X(prop help creator:user-act-help)
  145. X(label "record from microphone...")
  146. X(x -0.75)
  147. X(y 0.75)
  148. X(w 4.7)
  149. X(downfunc move-then-resize)
  150. X)
  151. X)
  152. X)
  153. X(pnl_wide_button (name "playbackbutton")
  154. X(prop help creator:user-act-help)
  155. X(label "playback to speaker")
  156. X(x 0.25)
  157. X(y 2)
  158. X(w 5.15)
  159. X(downfunc move-then-resize)
  160. X)
  161. X(pnl_wide_button (name "quitbutton")
  162. X(prop help creator:user-act-help)
  163. X(label "quit")
  164. X(x 0.25)
  165. X(y 0.25)
  166. X(w 1.75)
  167. X(downfunc move-then-resize)
  168. X)
  169. X)
  170. X)
  171. X;;; Local Variables:
  172. X;;; mode: scheme
  173. X;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3))
  174. X;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")"))
  175. X;;; eval: (indent-region (point-min) (point-max) nil)
  176. X;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer))
  177. X;;; End:
  178. EOF
  179. fi
  180. if test -s 'demo/sgi/gl_panel/flying/light.s'
  181. then echo '*** I will not over-write existing file demo/sgi/gl_panel/flying/light.s'
  182. else
  183. echo 'x - demo/sgi/gl_panel/flying/light.s'
  184. sed 's/^X//' > 'demo/sgi/gl_panel/flying/light.s' << 'EOF'
  185. X;;; This file was automatically generated by the panel editor.
  186. X;;; If you read it into gnu emacs, it will automagically format itself.
  187. X
  188. X(panel (prop help creator:user-panel-help)
  189. X(prop user-panel #t)
  190. X(label "Light Sources")
  191. X(al (pnl_hslider (name "X")
  192. X(prop help creator:user-act-help)
  193. X(label "x")
  194. X(y 4)
  195. X(w 3.3)
  196. X(h 0.4)
  197. X(val 0.50)
  198. X(labeltype 0)
  199. X(downfunc move-then-resize)
  200. X)
  201. X(pnl_hslider (name "Y")
  202. X(prop help creator:user-act-help)
  203. X(label "y")
  204. X(y 3.5)
  205. X(w 3.3)
  206. X(h 0.4)
  207. X(val 0.50)
  208. X(labeltype 0)
  209. X(downfunc move-then-resize)
  210. X)
  211. X(pnl_hslider (name "Z")
  212. X(prop help creator:user-act-help)
  213. X(label "z")
  214. X(y 3)
  215. X(w 3.3)
  216. X(h 0.4)
  217. X(val 0.50)
  218. X(labeltype 0)
  219. X(downfunc move-then-resize)
  220. X)
  221. X(pnl_radio_button (name "light2")
  222. X(prop help creator:user-act-help)
  223. X(label "light 2")
  224. X(x 5)
  225. X(y 4)
  226. X(h 0.36)
  227. X(downfunc move-then-resize)
  228. X)
  229. X(pnl_radio_button (name "light1")
  230. X(prop help creator:user-act-help)
  231. X(label "light 1")
  232. X(x 5)
  233. X(y 4.5)
  234. X(h 0.36)
  235. X(downfunc move-then-resize)
  236. X)
  237. X(pnl_toggle_button (name "local")
  238. X(prop help creator:user-act-help)
  239. X(label "local")
  240. X(x 5)
  241. X(y 2.75)
  242. X(downfunc move-then-resize)
  243. X)
  244. X(pnl_filled_hslider (name "B")
  245. X(prop help creator:user-act-help)
  246. X(label "B")
  247. X(w 3.3)
  248. X(h 0.4)
  249. X(labeltype 0)
  250. X(downfunc move-then-resize)
  251. X)
  252. X(pnl_filled_hslider (name "G")
  253. X(prop help creator:user-act-help)
  254. X(label "G")
  255. X(y 0.5)
  256. X(w 3.3)
  257. X(h 0.4)
  258. X(labeltype 0)
  259. X(downfunc move-then-resize)
  260. X)
  261. X(pnl_filled_hslider (name "R")
  262. X(prop help creator:user-act-help)
  263. X(label "R")
  264. X(y 1)
  265. X(w 3.3)
  266. X(h 0.4)
  267. X(labeltype 0)
  268. X(downfunc move-then-resize)
  269. X)
  270. X)
  271. X)
  272. X;;; Local Variables:
  273. X;;; mode: scheme
  274. X;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3))
  275. X;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")"))
  276. X;;; eval: (indent-region (point-min) (point-max) nil)
  277. X;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer))
  278. X;;; End:
  279. EOF
  280. fi
  281. if test -s 'demo/sgi/gl_panel/flying/panel.s'
  282. then echo '*** I will not over-write existing file demo/sgi/gl_panel/flying/panel.s'
  283. else
  284. echo 'x - demo/sgi/gl_panel/flying/panel.s'
  285. sed 's/^X//' > 'demo/sgi/gl_panel/flying/panel.s' << 'EOF'
  286. X;;; This file was automatically generated by the panel editor.
  287. X;;; If you read it into gnu emacs, it will automagically format itself.
  288. X
  289. X(panel (prop help creator:user-panel-help)
  290. X(prop user-panel #t)
  291. X(label "Panel Control")
  292. X(x 394)
  293. X(y 622)
  294. X(al (pnl_radio_button (name "button4")
  295. X(prop help creator:user-act-help)
  296. X(y 2.5)
  297. X(h 0.36)
  298. X(downfunc move-then-resize)
  299. X)
  300. X(pnl_radio_button (name "button3")
  301. X(prop help creator:user-act-help)
  302. X(y 3)
  303. X(h 0.36)
  304. X(downfunc move-then-resize)
  305. X)
  306. X(pnl_radio_button (name "button2")
  307. X(prop help creator:user-act-help)
  308. X(y 3.5)
  309. X(h 0.36)
  310. X(downfunc move-then-resize)
  311. X)
  312. X(pnl_radio_button (name "button1")
  313. X(prop help creator:user-act-help)
  314. X(y 4)
  315. X(h 0.36)
  316. X(downfunc move-then-resize)
  317. X)
  318. X(pnl_wide_button (name "title1")
  319. X(prop help creator:user-act-help)
  320. X(x 0.75)
  321. X(y 4.75)
  322. X(w 2.44)
  323. X(downfunc move-then-resize)
  324. X)
  325. X(pnl_wide_button (name "title2")
  326. X(prop help creator:user-act-help)
  327. X(x 3.5)
  328. X(y 4.75)
  329. X(w 2.44)
  330. X(downfunc move-then-resize)
  331. X)
  332. X(pnl_wide_button (name "title3")
  333. X(prop help creator:user-act-help)
  334. X(x 6.25)
  335. X(y 4.75)
  336. X(w 2.44)
  337. X(downfunc move-then-resize)
  338. X)
  339. X(pnl_wide_button (name "title4")
  340. X(prop help creator:user-act-help)
  341. X(x 9)
  342. X(y 4.75)
  343. X(w 2.44)
  344. X(downfunc move-then-resize)
  345. X)
  346. X(pnl_button (name "root")
  347. X(prop help creator:user-act-help)
  348. X(label "R")
  349. X(y 4.75)
  350. X(labeltype 16)
  351. X(downfunc move-then-resize)
  352. X)
  353. X)
  354. X)
  355. X;;; Local Variables:
  356. X;;; mode: scheme
  357. X;;; eval: (save-excursion (goto-char (point-min)) (kill-line 3))
  358. X;;; eval: (save-excursion (goto-char (point-min)) (replace-regexp "[ \n]*)" ")"))
  359. X;;; eval: (indent-region (point-min) (point-max) nil)
  360. X;;; eval: (progn (kill-line -3) (delete-backward-char 1) (save-buffer))
  361. X;;; End:
  362. EOF
  363. fi
  364. if test -s 'lib/Abstract.py'
  365. then echo '*** I will not over-write existing file lib/Abstract.py'
  366. else
  367. echo 'x - lib/Abstract.py'
  368. sed 's/^X//' > 'lib/Abstract.py' << 'EOF'
  369. X# Abstract classes for parents and children.
  370. X#
  371. X# Do not use as base class -- this is for documentation only.
  372. X#
  373. X# Note that the tree must be built top down (create the parent,
  374. X# then add the children).
  375. X#
  376. X# Also note that the creation methods are not standardized --
  377. X# these have extra parameters dependent on the widget type.
  378. X# For historical reasons, button creation methods are called
  379. X# define() while split creation methods are called create().
  380. X
  381. Xclass AbstractParent():
  382. X    #
  383. X    # Upcalls from child to parent
  384. X    #
  385. X    def addchild(self, child): unimpl()
  386. X    def delchild(self, child): unimpl()
  387. X    #
  388. X    def need_mouse(self, child): unimpl()
  389. X    def no_mouse(self, child): unimpl()
  390. X    #
  391. X    def need_timer(self, child): unimpl()
  392. X    def no_timer(self, child): unimpl()
  393. X    #
  394. X    # XXX need_kbd, no_kbd; focus???
  395. X    #
  396. X    def begindrawing(self): return unimpl()
  397. X    def beginmeasuring(self): return unimpl()
  398. X    #
  399. X    def change(self, area): unimpl()
  400. X    def scroll(self, (area, (dh, dv))): unimpl()
  401. X    def settimer(self, itimer): unimpl()
  402. X
  403. Xclass AbstractChild():
  404. X    #
  405. X    # Downcalls from parent to child
  406. X    #
  407. X    def destroy(self): unimpl()
  408. X    #
  409. X    def minsize(self, m): return unimpl()
  410. X    def getbounds(self): return unimpl()
  411. X    def setbounds(self, bounds): unimpl()
  412. X    def draw(self, (d, area)): unimpl()
  413. X    #
  414. X    # Downcalls only made after certain upcalls
  415. X    #
  416. X    def mouse_down(self, detail): unimpl()
  417. X    def mouse_move(self, detail): unimpl()
  418. X    def mouse_up(self, detail): unimpl()
  419. X    #
  420. X    def timer(self): unimpl()
  421. X
  422. X# A "Split" is a child that manages one or more children.
  423. X# (This terminology is due to DEC SRC, except for CSplits.)
  424. X# A child of a split may be another split, a button, a slider, etc.
  425. X# Certain upcalls and downcalls can be handled transparently, but
  426. X# for others (e.g., all geometry related calls) this is not possible.
  427. X
  428. Xclass AbstractSplit() = AbstractChild(), AbstractParent():
  429. X    pass
  430. EOF
  431. fi
  432. if test -s 'lib/StripChart.py'
  433. then echo '*** I will not over-write existing file lib/StripChart.py'
  434. else
  435. echo 'x - lib/StripChart.py'
  436. sed 's/^X//' > 'lib/StripChart.py' << 'EOF'
  437. X# Module 'StripChart'
  438. X
  439. Ximport rect
  440. Xfrom Buttons import LabelAppearance, NoReactivity
  441. X
  442. X# A StripChart doesn't really look like a label but it needs a base class.
  443. X# LabelAppearance allows it to be disabled and hilited.
  444. X
  445. Xclass StripChart() = LabelAppearance(), NoReactivity():
  446. X    #
  447. X    def define(self, (parent, scale)):
  448. X        self.parent = parent
  449. X        parent.addchild(self)
  450. X        self.init_appearance()
  451. X        self.init_reactivity()
  452. X        self.ydata = []
  453. X        self.scale = scale
  454. X        self.resetbounds()
  455. X        return self
  456. X    #
  457. X    def setbounds(self, bounds):
  458. X        LabelAppearance.setbounds(self, bounds)
  459. X        self.resetbounds()
  460. X    #
  461. X    def resetbounds(self):
  462. X        (left, top), (right, bottom) = self.bounds
  463. X        self.width = right-left
  464. X        self.height = bottom-top
  465. X        excess = len(self.ydata) - self.width
  466. X        if excess > 0:
  467. X            del self.ydata[:excess]
  468. X        elif excess < 0:
  469. X            while len(self.ydata) < self.width:
  470. X                self.ydata.insert(0, 0)
  471. X    #
  472. X    def append(self, y):
  473. X        self.ydata.append(y)
  474. X        excess = len(self.ydata) - self.width
  475. X        if excess > 0:
  476. X            del self.ydata[:excess]
  477. X            if self.bounds <> rect.empty:
  478. X                self.parent.scroll(self.bounds, (-excess, 0))
  479. X        if self.bounds <> rect.empty:
  480. X            (left, top), (right, bottom) = self.bounds
  481. X            i = len(self.ydata)
  482. X            area = (left+i-1, top), (left+i, bottom)
  483. X            self.draw(self.parent.begindrawing(), area)
  484. X    #
  485. X    def draw(self, (d, area)):
  486. X        area = rect.intersect(area, self.bounds)
  487. X        if area = rect.empty:
  488. X            print 'mt'
  489. X            return
  490. X        d.cliprect(area)
  491. X        d.erase(self.bounds)
  492. X        (a_left, a_top), (a_right, a_bottom) = area
  493. X        (left, top), (right, bottom) = self.bounds
  494. X        height = bottom - top
  495. X        i1 = a_left - left
  496. X        i2 = a_right - left
  497. X        for i in range(max(0, i1), min(len(self.ydata), i2)):
  498. X            split = bottom-self.ydata[i]*height/self.scale
  499. X            d.paint((left+i, split), (left+i+1, bottom))
  500. X        if not self.enabled:
  501. X            self.flipenable(d)
  502. X        if self.hilited:
  503. X            self.fliphilite(d)
  504. X        d.noclip()
  505. EOF
  506. fi
  507. if test -s 'lib/cmp.py'
  508. then echo '*** I will not over-write existing file lib/cmp.py'
  509. else
  510. echo 'x - lib/cmp.py'
  511. sed 's/^X//' > 'lib/cmp.py' << 'EOF'
  512. X# Module 'cmp'
  513. X
  514. X# Efficiently compare files, boolean outcome only (equal / not equal).
  515. X
  516. X# Tricks (used in this order):
  517. X#    - Files with identical type, size & mtime are assumed to be clones
  518. X#    - Files with different type or size cannot be identical
  519. X#    - We keep a cache of outcomes of earlier comparisons
  520. X#    - We don't fork a process to run 'cmp' but read the files ourselves
  521. X
  522. Ximport posix
  523. X
  524. Xcache = {}
  525. X
  526. Xdef cmp(f1, f2): # Compare two files, use the cache if possible.
  527. X    # Return 1 for identical files, 0 for different.
  528. X    # Raise exceptions if either file could not be statted, read, etc.
  529. X    s1, s2 = sig(posix.stat(f1)), sig(posix.stat(f2))
  530. X    if s1[0] <> 8 or s2[0] <> 8:
  531. X        # Either is a not a plain file -- always report as different
  532. X        return 0
  533. X    if s1 = s2:
  534. X        # type, size & mtime match -- report same
  535. X        return 1
  536. X    if s1[:2] <> s2[:2]: # Types or sizes differ, don't bother
  537. X        # types or sizes differ -- report different
  538. X        return 0
  539. X    # same type and size -- look in the cache
  540. X    key = f1 + ' ' + f2
  541. X    try:
  542. X        cs1, cs2, outcome = cache[key]
  543. X        # cache hit
  544. X        if s1 = cs1 and s2 = cs2:
  545. X            # cached signatures match
  546. X            return outcome
  547. X        # stale cached signature(s)
  548. X    except RuntimeError:
  549. X        # cache miss
  550. X        pass
  551. X    # really compare
  552. X    outcome = do_cmp(f1, f2)
  553. X    cache[key] = s1, s2, outcome
  554. X    return outcome
  555. X
  556. Xdef sig(st): # Return signature (i.e., type, size, mtime) from raw stat data
  557. X    # 0-5: st_mode, st_ino, st_dev, st_nlink, st_uid, st_gid
  558. X    # 6-9: st_size, st_atime, st_mtime, st_ctime
  559. X    type = st[0] / 4096
  560. X    size = st[6]
  561. X    mtime = st[8]
  562. X    return type, size, mtime
  563. X
  564. Xdef do_cmp(f1, f2): # Compare two files, really
  565. X    bufsize = 8096 # Could be tuned
  566. X    fp1 = open(f1, 'r')
  567. X    fp2 = open(f2, 'r')
  568. X    while 1:
  569. X        b1 = fp1.read(bufsize)
  570. X        b2 = fp2.read(bufsize)
  571. X        if b1 <> b2: return 0
  572. X        if not b1: return 1
  573. EOF
  574. fi
  575. if test -s 'lib/commands.py'
  576. then echo '*** I will not over-write existing file lib/commands.py'
  577. else
  578. echo 'x - lib/commands.py'
  579. sed 's/^X//' > 'lib/commands.py' << 'EOF'
  580. X# Module 'commands'
  581. X#
  582. X# Various tools for executing commands and looking at their output and status.
  583. X
  584. Ximport rand
  585. Ximport posix
  586. Ximport stat
  587. Ximport path
  588. X
  589. X
  590. X# Get 'ls -l' status for an object into a string
  591. X#
  592. Xdef getstatus(file):
  593. X    return getoutput('ls -ld' + mkarg(file))
  594. X
  595. X
  596. X# Get the output from a shell command into a string.
  597. X# The exit status is ignored; a trailing newline is stripped.
  598. X# Assume the command will work with ' >tempfile 2>&1' appended.
  599. X# XXX This should use posix.popen() instead, should it exist.
  600. X#
  601. Xdef getoutput(cmd):
  602. X    return getstatusoutput(cmd)[1]
  603. X
  604. X
  605. X# Ditto but preserving the exit status.
  606. X# Returns a pair (sts, output)
  607. X#
  608. Xdef getstatusoutput(cmd):
  609. X    tmp = '/usr/tmp/wdiff' + `rand.rand()`
  610. X    sts = -1
  611. X    try:
  612. X        sts = posix.system(cmd + ' >' + tmp + ' 2>&1')
  613. X        text = readfile(tmp)
  614. X    finally:
  615. X        altsts = posix.system('rm -f ' + tmp)
  616. X    if text[-1:] = '\n': text = text[:-1]
  617. X    return sts, text
  618. X
  619. X
  620. X# Return a string containing a file's contents.
  621. X#
  622. Xdef readfile(fn):
  623. X    st = posix.stat(fn)
  624. X    size = st[stat.ST_SIZE]
  625. X    if not size: return ''
  626. X    try:
  627. X        fp = open(fn, 'r')
  628. X    except:
  629. X        raise posix.error, 'readfile(' + fn + '): open failed'
  630. X    try:
  631. X        return fp.read(size)
  632. X    except:
  633. X        raise posix.error, 'readfile(' + fn + '): read failed'
  634. X
  635. X
  636. X# Make command argument from directory and pathname (prefix space, add quotes).
  637. X#
  638. Xdef mk2arg(head, x):
  639. X    return mkarg(path.cat(head, x))
  640. X
  641. X
  642. X# Make a shell command argument from a string.
  643. X# Two strategies: enclose in single quotes if it contains none;
  644. X# otherwis, enclose in double quotes and prefix quotable characters
  645. X# with backslash.
  646. X#
  647. Xdef mkarg(x):
  648. X    if '\'' not in x:
  649. X        return ' \'' + x + '\''
  650. X    s = ' "'
  651. X    for c in x:
  652. X        if c in '\\$"':
  653. X            s = s + '\\'
  654. X        s = s + c
  655. X    s = s + '"'
  656. X    return s
  657. EOF
  658. fi
  659. if test -s 'lib/getopt.py'
  660. then echo '*** I will not over-write existing file lib/getopt.py'
  661. else
  662. echo 'x - lib/getopt.py'
  663. sed 's/^X//' > 'lib/getopt.py' << 'EOF'
  664. X# module getopt -- Standard command line processing.
  665. X
  666. X# Function getopt.getopt() has a different interface but provides the
  667. X# same functionality as the Unix getopt() function.
  668. X
  669. X# It has two arguments: the first should be argv[1:] (it doesn't want
  670. X# the script name), the second the string of option letters as passed
  671. X# to Unix getopt() (i.e., a string of allowable option letters, with
  672. X# options requiring an argument followed by a colon).
  673. X
  674. X# It raises the exception getopt.error with a string argument if it
  675. X# detects an error.
  676. X
  677. X# It returns two items:
  678. X# (1)    a list of pairs (option, option_argument) giving the options in
  679. X#    the order in which they were specified.  (I'd use a dictionary
  680. X#    but applications may depend on option order or multiple
  681. X#    occurrences.)  Boolean options have '' as option_argument.
  682. X# (2)    the list of remaining arguments (may be empty).
  683. X
  684. Xerror = 'getopt error'
  685. X
  686. Xdef getopt(args, options):
  687. X    list = []
  688. X    while args and args[0][0] = '-' and args[0] <> '-':
  689. X        if args[0] = '--':
  690. X            args = args[1:]
  691. X            break
  692. X        optstring, args = args[0][1:], args[1:]
  693. X        while optstring <> '':
  694. X            opt, optstring = optstring[0], optstring[1:]
  695. X            if classify(opt, options): # May raise exception as well
  696. X                if optstring = '':
  697. X                    if not args:
  698. X                        raise error, 'option -' + opt + ' requires argument'
  699. X                    optstring, args = args[0], args[1:]
  700. X                optarg, optstring = optstring, ''
  701. X            else:
  702. X                optarg = ''
  703. X            list.append('-' + opt, optarg)
  704. X    return list, args
  705. X
  706. Xdef classify(opt, options): # Helper to check type of option
  707. X    for i in range(len(options)):
  708. X    if opt = options[i] <> ':':
  709. X        return options[i+1:i+2] = ':'
  710. X    raise error, 'option -' + opt + ' not recognized'
  711. EOF
  712. fi
  713. if test -s 'lib/rect.py'
  714. then echo '*** I will not over-write existing file lib/rect.py'
  715. else
  716. echo 'x - lib/rect.py'
  717. sed 's/^X//' > 'lib/rect.py' << 'EOF'
  718. X# Module 'rect'.
  719. X#
  720. X# Operations on rectangles.
  721. X# There is some normalization: all results return the object 'empty'
  722. X# if their result would contain no points.
  723. X
  724. X
  725. X# Exception.
  726. X#
  727. Xerror = 'rect.error'
  728. X
  729. X
  730. X# The empty rectangle.
  731. X#
  732. Xempty = (0, 0), (0, 0)
  733. X
  734. X
  735. X# Check if a rectangle is empty.
  736. X#
  737. Xdef is_empty((left, top), (right, bottom)):
  738. X    return left >= right or top >= bottom
  739. X
  740. X
  741. X# Compute the intersection or two or more rectangles.
  742. X# This works with a list or tuple argument.
  743. X#
  744. Xdef intersect(list):
  745. X    if not list: raise error, 'intersect called with empty list'
  746. X    if is_empty(list[0]): return empty
  747. X    (left, top), (right, bottom) = list[0]
  748. X    for rect in list[1:]:
  749. X        if is_empty(rect):
  750. X            return empty
  751. X        (l, t), (r, b) = rect
  752. X        if left < l: left = l
  753. X        if top < t: top = t
  754. X        if right > r: right = r
  755. X        if bottom > b: bottom = b
  756. X        if is_empty((left, top), (right, bottom)):
  757. X            return empty
  758. X    return (left, top), (right, bottom)
  759. X
  760. X
  761. X# Compute the smallest rectangle containing all given rectangles.
  762. X# This works with a list or tuple argument.
  763. X#
  764. Xdef union(list):
  765. X    (left, top), (right, bottom) = empty
  766. X    for (l, t), (r, b) in list[1:]:
  767. X        if not is_empty((l, t), (r, b)):
  768. X            if l < left: left = l
  769. X            if t < top: top = t
  770. X            if r > right: right = r
  771. X            if b > bottom: bottom = b
  772. X    res = (left, top), (right, bottom)
  773. X    if is_empty(res):
  774. X        return empty
  775. X    return res
  776. X
  777. X
  778. X# Check if a point is in a rectangle.
  779. X#
  780. Xdef pointinrect((h, v), ((left, top), (right, bottom))):
  781. X    return left <= h < right and top <= v < bottom
  782. X
  783. X
  784. X# Return a rectangle that is dh, dv inside another
  785. X#
  786. Xdef inset(((left, top), (right, bottom)), (dh, dv)):
  787. X    left = left + dh
  788. X    top = top + dv
  789. X    right = right - dh
  790. X    bottom = bottom - dv
  791. X    r = (left, top), (right, bottom)
  792. X    if is_empty(r):
  793. X        return empty
  794. X    else:
  795. X        return r
  796. X
  797. X
  798. X# Conversions between rectangles and 'geometry tuples',
  799. X# given as origin (h, v) and dimensions (width, height).
  800. X#
  801. Xdef rect2geom((left, top), (right, bottom)):
  802. X    return (left, top), (right-left, bottom-top)
  803. X
  804. Xdef geom2rect((h, v), (width, height)):
  805. X    return (h, v), (h+width, v+height)
  806. EOF
  807. fi
  808. if test -s 'lib/selection.py'
  809. then echo '*** I will not over-write existing file lib/selection.py'
  810. else
  811. echo 'x - lib/selection.py'
  812. sed 's/^X//' > 'lib/selection.py' << 'EOF'
  813. X# DAWKINS' BLIND WATCHMAKER -- "METHINKS IT IS LIKE A WEASEL" EXAMPLE
  814. X#
  815. X# Start with a random phrase.  Successively:
  816. X# Breed a next generation by copying with small mutations.
  817. X# Choose the member of the next generation that most closely resembles
  818. X# the target phrase to start breeding the next generation.
  819. X# How many generations will it take before the target is reached?
  820. X
  821. Xfrom whrandom import random
  822. X
  823. X# Parameters determining the problem space
  824. XTarget = 'methinks it is like a weasel'
  825. XAlphabet = ' abcdefghijklmnopqrstuvwxyz'
  826. X
  827. X# Parameters to play with
  828. XGenerationSize = 100
  829. XMutationChance = 1.0/28.0
  830. X
  831. XIndexSet = range(len(Target))    # Used to speed up loops
  832. X
  833. Xdef choice(sequence):
  834. X    n = len(sequence)
  835. X    i = int(random() * float(n)) % n
  836. X    return sequence[i]
  837. X
  838. Xdef random_phrase():
  839. X    phrase = ''
  840. X    for i in IndexSet:
  841. X        phrase = phrase + choice(Alphabet)
  842. X    return phrase
  843. X
  844. Xdef mutate_phrase(phrase):
  845. X    mutant = phrase
  846. X    for i in range(int(0.5 + MutationChance*float(len(phrase)))):
  847. X        i = choice(IndexSet)
  848. X        c = choice(Alphabet)
  849. X        mutant = mutant[:i] + c + mutant[i+1:]
  850. X    #print `mutant`
  851. X    return mutant
  852. X
  853. Xdef matching_factor(phrase):
  854. X    factor = 0
  855. X    for i in IndexSet:
  856. X        if phrase[i] = Target[i]: factor = factor + 1
  857. X    return factor
  858. X
  859. Xdef breed_generation(phrase):
  860. X    generation = [phrase]
  861. X    while len(generation) < GenerationSize:
  862. X        generation.append(mutate_phrase(phrase))
  863. X    return generation
  864. X
  865. Xdef select_best(generation):
  866. X    factor, selected = -1, ''
  867. X    for phrase in generation:
  868. X        f = matching_factor(phrase)
  869. X        if f > factor:
  870. X            factor, selected = f, phrase
  871. X    return selected
  872. X
  873. Xdef main():
  874. X    gen = 0
  875. X    phrase = random_phrase()
  876. X    print gen, `phrase`
  877. X    while phrase <> Target:
  878. X        next_generation = breed_generation(phrase)
  879. X        #print next_generation
  880. X        phrase = select_best(next_generation)
  881. X        gen = gen+1
  882. X        print gen, `phrase`
  883. X
  884. Xmain()
  885. EOF
  886. fi
  887. if test -s 'lib/statcache.py'
  888. then echo '*** I will not over-write existing file lib/statcache.py'
  889. else
  890. echo 'x - lib/statcache.py'
  891. sed 's/^X//' > 'lib/statcache.py' << 'EOF'
  892. X# Module 'statcache'
  893. X#
  894. X# Maintain a cache of file stats.
  895. X# There are functions to reset the cache or to selectively remove items.
  896. X
  897. Ximport posix
  898. Xfrom stat import *
  899. X
  900. X# The cache.
  901. X# Keys are pathnames, values are `posix.stat' outcomes.
  902. X#
  903. Xcache = {}
  904. X
  905. X
  906. X# Stat a file, possibly out of the cache.
  907. X#
  908. Xdef stat(path):
  909. X    if cache.has_key(path):
  910. X        return cache[path]
  911. X    cache[path] = ret = posix.stat(path)
  912. X    return ret
  913. X
  914. X
  915. X# Reset the cache completely.
  916. X# Hack: to reset a global variable, we import this module.
  917. X#
  918. Xdef reset():
  919. X    import statcache
  920. X    # Check that we really imported the same module
  921. X    if cache is not statcache.cache:
  922. X        raise 'sorry, statcache identity crisis'
  923. X    statcache.cache = {}
  924. X
  925. X
  926. X# Remove a given item from the cache, if it exists.
  927. X#
  928. Xdef forget(path):
  929. X    if cache.has_key(path):
  930. X        del cache[path]
  931. X
  932. X
  933. X# Remove all pathnames with a given prefix.
  934. X#
  935. Xdef forget_prefix(prefix):
  936. X    n = len(prefix)
  937. X    for path in cache.keys():
  938. X        if path[:n] = prefix:
  939. X            del cache[path]
  940. X
  941. X
  942. X# Forget about a directory and all entries in it, but not about
  943. X# entries in subdirectories.
  944. X#
  945. Xdef forget_dir(prefix):
  946. X    if prefix[-1:] = '/' and prefix <> '/':
  947. X        prefix = prefix[:-1]
  948. X    forget(prefix)
  949. X    if prefix[-1:] <> '/':
  950. X        prefix = prefix + '/'
  951. X    n = len(prefix)
  952. X    for path in cache.keys():
  953. X        if path[:n] = prefix:
  954. X            rest = path[n:]
  955. X            if rest[-1:] = '/': rest = rest[:-1]
  956. X            if '/' not in rest:
  957. X                del cache[path]
  958. X
  959. X
  960. X# Remove all pathnames except with a given prefix.
  961. X# Normally used with prefix = '/' after a chdir().
  962. X#
  963. Xdef forget_except_prefix(prefix):
  964. X    n = len(prefix)
  965. X    for path in cache.keys():
  966. X        if path[:n] <> prefix:
  967. X            del cache[path]
  968. X
  969. X
  970. X# Check for directory.
  971. X#
  972. Xdef isdir(path):
  973. X    try:
  974. X        st = stat(path)
  975. X    except posix.error:
  976. X        return 0
  977. X    return S_ISDIR(st[ST_MODE])
  978. EOF
  979. fi
  980. if test -s 'src/allobjects.h'
  981. then echo '*** I will not over-write existing file src/allobjects.h'
  982. else
  983. echo 'x - src/allobjects.h'
  984. sed 's/^X//' > 'src/allobjects.h' << 'EOF'
  985. X/***********************************************************
  986. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  987. XNetherlands.
  988. X
  989. X                        All Rights Reserved
  990. X
  991. XPermission to use, copy, modify, and distribute this software and its 
  992. Xdocumentation for any purpose and without fee is hereby granted, 
  993. Xprovided that the above copyright notice appear in all copies and that
  994. Xboth that copyright notice and this permission notice appear in 
  995. Xsupporting documentation, and that the names of Stichting Mathematisch
  996. XCentrum or CWI not be used in advertising or publicity pertaining to
  997. Xdistribution of the software without specific, written prior permission.
  998. X
  999. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1000. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1001. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1002. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1003. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1004. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1005. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1006. X
  1007. X******************************************************************/
  1008. X
  1009. X/* "allobjects.c" -- Source for precompiled header "allobjects.h" */
  1010. X
  1011. X#include <stdio.h>
  1012. X#include <string.h>
  1013. X
  1014. X#include "PROTO.h"
  1015. X
  1016. X#include "object.h"
  1017. X#include "objimpl.h"
  1018. X
  1019. X#include "intobject.h"
  1020. X#include "floatobject.h"
  1021. X#include "stringobject.h"
  1022. X#include "tupleobject.h"
  1023. X#include "listobject.h"
  1024. X#include "dictobject.h"
  1025. X#include "methodobject.h"
  1026. X#include "moduleobject.h"
  1027. X#include "funcobject.h"
  1028. X#include "classobject.h"
  1029. X#include "fileobject.h"
  1030. X
  1031. X#include "errors.h"
  1032. X#include "malloc.h"
  1033. X
  1034. Xextern char *strdup PROTO((const char *));
  1035. EOF
  1036. fi
  1037. if test -s 'src/bitset.h'
  1038. then echo '*** I will not over-write existing file src/bitset.h'
  1039. else
  1040. echo 'x - src/bitset.h'
  1041. sed 's/^X//' > 'src/bitset.h' << 'EOF'
  1042. X/***********************************************************
  1043. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1044. XNetherlands.
  1045. X
  1046. X                        All Rights Reserved
  1047. X
  1048. XPermission to use, copy, modify, and distribute this software and its 
  1049. Xdocumentation for any purpose and without fee is hereby granted, 
  1050. Xprovided that the above copyright notice appear in all copies and that
  1051. Xboth that copyright notice and this permission notice appear in 
  1052. Xsupporting documentation, and that the names of Stichting Mathematisch
  1053. XCentrum or CWI not be used in advertising or publicity pertaining to
  1054. Xdistribution of the software without specific, written prior permission.
  1055. X
  1056. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1057. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1058. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1059. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1060. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1061. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1062. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1063. X
  1064. X******************************************************************/
  1065. X
  1066. X/* Bitset interface */
  1067. X
  1068. X#define BYTE        char
  1069. X
  1070. Xtypedef BYTE *bitset;
  1071. X
  1072. Xbitset newbitset PROTO((int nbits));
  1073. Xvoid delbitset PROTO((bitset bs));
  1074. X/* int testbit PROTO((bitset bs, int ibit)); /* Now a macro, see below */
  1075. Xint addbit PROTO((bitset bs, int ibit)); /* Returns 0 if already set */
  1076. Xint samebitset PROTO((bitset bs1, bitset bs2, int nbits));
  1077. Xvoid mergebitset PROTO((bitset bs1, bitset bs2, int nbits));
  1078. X
  1079. X#define BITSPERBYTE    (8*sizeof(BYTE))
  1080. X#define NBYTES(nbits)    (((nbits) + BITSPERBYTE - 1) / BITSPERBYTE)
  1081. X
  1082. X#define BIT2BYTE(ibit)    ((ibit) / BITSPERBYTE)
  1083. X#define BIT2SHIFT(ibit)    ((ibit) % BITSPERBYTE)
  1084. X#define BIT2MASK(ibit)    (1 << BIT2SHIFT(ibit))
  1085. X#define BYTE2BIT(ibyte)    ((ibyte) * BITSPERBYTE)
  1086. X
  1087. X#define testbit(ss, ibit) (((ss)[BIT2BYTE(ibit)] & BIT2MASK(ibit)) != 0)
  1088. EOF
  1089. fi
  1090. if test -s 'src/cgensupport.h'
  1091. then echo '*** I will not over-write existing file src/cgensupport.h'
  1092. else
  1093. echo 'x - src/cgensupport.h'
  1094. sed 's/^X//' > 'src/cgensupport.h' << 'EOF'
  1095. X/***********************************************************
  1096. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1097. XNetherlands.
  1098. X
  1099. X                        All Rights Reserved
  1100. X
  1101. XPermission to use, copy, modify, and distribute this software and its 
  1102. Xdocumentation for any purpose and without fee is hereby granted, 
  1103. Xprovided that the above copyright notice appear in all copies and that
  1104. Xboth that copyright notice and this permission notice appear in 
  1105. Xsupporting documentation, and that the names of Stichting Mathematisch
  1106. XCentrum or CWI not be used in advertising or publicity pertaining to
  1107. Xdistribution of the software without specific, written prior permission.
  1108. X
  1109. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1110. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1111. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1112. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1113. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1114. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1115. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1116. X
  1117. X******************************************************************/
  1118. X
  1119. X/* Definitions used by cgen output */
  1120. X
  1121. Xtypedef char *string;
  1122. X
  1123. X#define mknewlongobject(x) newintobject(x)
  1124. X#define mknewshortobject(x) newintobject((long)x)
  1125. X#define mknewfloatobject(x) newfloatobject(x)
  1126. X
  1127. Xextern object *mknewcharobject PROTO((int c));
  1128. X
  1129. Xextern int getiobjectarg PROTO((object *args, int nargs, int i, object **p_a));
  1130. Xextern int getilongarg PROTO((object *args, int nargs, int i, long *p_a));
  1131. Xextern int getishortarg PROTO((object *args, int nargs, int i, short *p_a));
  1132. Xextern int getifloatarg PROTO((object *args, int nargs, int i, float *p_a));
  1133. Xextern int getistringarg PROTO((object *args, int nargs, int i, string *p_a));
  1134. EOF
  1135. fi
  1136. if test -s 'src/classobject.h'
  1137. then echo '*** I will not over-write existing file src/classobject.h'
  1138. else
  1139. echo 'x - src/classobject.h'
  1140. sed 's/^X//' > 'src/classobject.h' << 'EOF'
  1141. X/***********************************************************
  1142. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1143. XNetherlands.
  1144. X
  1145. X                        All Rights Reserved
  1146. X
  1147. XPermission to use, copy, modify, and distribute this software and its 
  1148. Xdocumentation for any purpose and without fee is hereby granted, 
  1149. Xprovided that the above copyright notice appear in all copies and that
  1150. Xboth that copyright notice and this permission notice appear in 
  1151. Xsupporting documentation, and that the names of Stichting Mathematisch
  1152. XCentrum or CWI not be used in advertising or publicity pertaining to
  1153. Xdistribution of the software without specific, written prior permission.
  1154. X
  1155. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1156. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1157. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1158. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1159. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1160. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1161. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1162. X
  1163. X******************************************************************/
  1164. X
  1165. X/* Class object interface */
  1166. X
  1167. X/*
  1168. XClasses are really hacked in at the last moment.
  1169. XIt should be possible to use other object types as base classes,
  1170. Xbut currently it isn't.  We'll see if we can fix that later, sigh...
  1171. X*/
  1172. X
  1173. Xextern typeobject Classtype, Classmembertype, Classmethodtype;
  1174. X
  1175. X#define is_classobject(op) ((op)->ob_type == &Classtype)
  1176. X#define is_classmemberobject(op) ((op)->ob_type == &Classmembertype)
  1177. X#define is_classmethodobject(op) ((op)->ob_type == &Classmethodtype)
  1178. X
  1179. Xextern object *newclassobject PROTO((object *, object *));
  1180. Xextern object *newclassmemberobject PROTO((object *));
  1181. Xextern object *newclassmethodobject PROTO((object *, object *));
  1182. X
  1183. Xextern object *classmethodgetfunc PROTO((object *));
  1184. Xextern object *classmethodgetself PROTO((object *));
  1185. EOF
  1186. fi
  1187. if test -s 'src/compile.h'
  1188. then echo '*** I will not over-write existing file src/compile.h'
  1189. else
  1190. echo 'x - src/compile.h'
  1191. sed 's/^X//' > 'src/compile.h' << 'EOF'
  1192. X/***********************************************************
  1193. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1194. XNetherlands.
  1195. X
  1196. X                        All Rights Reserved
  1197. X
  1198. XPermission to use, copy, modify, and distribute this software and its 
  1199. Xdocumentation for any purpose and without fee is hereby granted, 
  1200. Xprovided that the above copyright notice appear in all copies and that
  1201. Xboth that copyright notice and this permission notice appear in 
  1202. Xsupporting documentation, and that the names of Stichting Mathematisch
  1203. XCentrum or CWI not be used in advertising or publicity pertaining to
  1204. Xdistribution of the software without specific, written prior permission.
  1205. X
  1206. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1207. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1208. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1209. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1210. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1211. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1212. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1213. X
  1214. X******************************************************************/
  1215. X
  1216. X/* Definitions for compiled intermediate code */
  1217. X
  1218. X
  1219. X/* An intermediate code fragment contains:
  1220. X   - a string that encodes the instructions,
  1221. X   - a list of the constants,
  1222. X   - and a list of the names used. */
  1223. X
  1224. Xtypedef struct {
  1225. X    OB_HEAD
  1226. X    stringobject *co_code;    /* instruction opcodes */
  1227. X    object *co_consts;    /* list of immutable constant objects */
  1228. X    object *co_names;    /* list of stringobjects */
  1229. X    object *co_filename;    /* string */
  1230. X} codeobject;
  1231. X
  1232. Xextern typeobject Codetype;
  1233. X
  1234. X#define is_codeobject(op) ((op)->ob_type == &Codetype)
  1235. X
  1236. X
  1237. X/* Public interface */
  1238. Xcodeobject *compile PROTO((struct _node *, char *));
  1239. EOF
  1240. fi
  1241. if test -s 'src/dictobject.h'
  1242. then echo '*** I will not over-write existing file src/dictobject.h'
  1243. else
  1244. echo 'x - src/dictobject.h'
  1245. sed 's/^X//' > 'src/dictobject.h' << 'EOF'
  1246. X/***********************************************************
  1247. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1248. XNetherlands.
  1249. X
  1250. X                        All Rights Reserved
  1251. X
  1252. XPermission to use, copy, modify, and distribute this software and its 
  1253. Xdocumentation for any purpose and without fee is hereby granted, 
  1254. Xprovided that the above copyright notice appear in all copies and that
  1255. Xboth that copyright notice and this permission notice appear in 
  1256. Xsupporting documentation, and that the names of Stichting Mathematisch
  1257. XCentrum or CWI not be used in advertising or publicity pertaining to
  1258. Xdistribution of the software without specific, written prior permission.
  1259. X
  1260. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1261. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1262. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1263. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1264. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1265. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1266. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1267. X
  1268. X******************************************************************/
  1269. X
  1270. X/*
  1271. XDictionary object type -- mapping from char * to object.
  1272. XNB: the key is given as a char *, not as a stringobject.
  1273. XThese functions set errno for errors.  Functions dictremove() and
  1274. Xdictinsert() return nonzero for errors, getdictsize() returns -1,
  1275. Xthe others NULL.  A successful call to dictinsert() calls INCREF()
  1276. Xfor the inserted item.
  1277. X*/
  1278. X
  1279. Xextern typeobject Dicttype;
  1280. X
  1281. X#define is_dictobject(op) ((op)->ob_type == &Dicttype)
  1282. X
  1283. Xextern object *newdictobject PROTO((void));
  1284. Xextern object *dictlookup PROTO((object *dp, char *key));
  1285. Xextern int dictinsert PROTO((object *dp, char *key, object *item));
  1286. Xextern int dictremove PROTO((object *dp, char *key));
  1287. Xextern int getdictsize PROTO((object *dp));
  1288. Xextern char *getdictkey PROTO((object *dp, int i));
  1289. Xextern object *getdictkeys PROTO((object *dp));
  1290. EOF
  1291. fi
  1292. if test -s 'src/errors.h'
  1293. then echo '*** I will not over-write existing file src/errors.h'
  1294. else
  1295. echo 'x - src/errors.h'
  1296. sed 's/^X//' > 'src/errors.h' << 'EOF'
  1297. X/***********************************************************
  1298. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1299. XNetherlands.
  1300. X
  1301. X                        All Rights Reserved
  1302. X
  1303. XPermission to use, copy, modify, and distribute this software and its 
  1304. Xdocumentation for any purpose and without fee is hereby granted, 
  1305. Xprovided that the above copyright notice appear in all copies and that
  1306. Xboth that copyright notice and this permission notice appear in 
  1307. Xsupporting documentation, and that the names of Stichting Mathematisch
  1308. XCentrum or CWI not be used in advertising or publicity pertaining to
  1309. Xdistribution of the software without specific, written prior permission.
  1310. X
  1311. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1312. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1313. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1314. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1315. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1316. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1317. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1318. X
  1319. X******************************************************************/
  1320. X
  1321. X/* Error handling definitions */
  1322. X
  1323. Xvoid err_set PROTO((object *));
  1324. Xvoid err_setval PROTO((object *, object *));
  1325. Xvoid err_setstr PROTO((object *, char *));
  1326. Xint err_occurred PROTO((void));
  1327. Xvoid err_get PROTO((object **, object **));
  1328. Xvoid err_clear PROTO((void));
  1329. X
  1330. X/* Predefined exceptions */
  1331. X
  1332. Xextern object *RuntimeError;
  1333. Xextern object *EOFError;
  1334. Xextern object *TypeError;
  1335. Xextern object *MemoryError;
  1336. Xextern object *NameError;
  1337. Xextern object *SystemError;
  1338. Xextern object *KeyboardInterrupt;
  1339. X
  1340. X/* Some more planned for the future */
  1341. X
  1342. X#define IndexError        RuntimeError
  1343. X#define KeyError        RuntimeError
  1344. X#define ZeroDivisionError    RuntimeError
  1345. X#define OverflowError        RuntimeError
  1346. X
  1347. X/* Convenience functions */
  1348. X
  1349. Xextern int err_badarg PROTO((void));
  1350. Xextern object *err_nomem PROTO((void));
  1351. Xextern object *err_errno PROTO((object *));
  1352. Xextern void err_input PROTO((int));
  1353. X
  1354. Xextern void err_badcall PROTO((void));
  1355. EOF
  1356. fi
  1357. if test -s 'src/grammar1.c'
  1358. then echo '*** I will not over-write existing file src/grammar1.c'
  1359. else
  1360. echo 'x - src/grammar1.c'
  1361. sed 's/^X//' > 'src/grammar1.c' << 'EOF'
  1362. X/***********************************************************
  1363. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1364. XNetherlands.
  1365. X
  1366. X                        All Rights Reserved
  1367. X
  1368. XPermission to use, copy, modify, and distribute this software and its 
  1369. Xdocumentation for any purpose and without fee is hereby granted, 
  1370. Xprovided that the above copyright notice appear in all copies and that
  1371. Xboth that copyright notice and this permission notice appear in 
  1372. Xsupporting documentation, and that the names of Stichting Mathematisch
  1373. XCentrum or CWI not be used in advertising or publicity pertaining to
  1374. Xdistribution of the software without specific, written prior permission.
  1375. X
  1376. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1377. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1378. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1379. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1380. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1381. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1382. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1383. X
  1384. X******************************************************************/
  1385. X
  1386. X/* Grammar subroutines needed by parser */
  1387. X
  1388. X#include "pgenheaders.h"
  1389. X#include "assert.h"
  1390. X#include "grammar.h"
  1391. X#include "token.h"
  1392. X
  1393. X/* Return the DFA for the given type */
  1394. X
  1395. Xdfa *
  1396. Xfinddfa(g, type)
  1397. X    grammar *g;
  1398. X    register int type;
  1399. X{
  1400. X    register int i;
  1401. X    register dfa *d;
  1402. X    
  1403. X    for (i = g->g_ndfas, d = g->g_dfa; --i >= 0; d++) {
  1404. X        if (d->d_type == type)
  1405. X            return d;
  1406. X    }
  1407. X    assert(0);
  1408. X    /* NOTREACHED */
  1409. X}
  1410. X
  1411. Xchar *
  1412. Xlabelrepr(lb)
  1413. X    label *lb;
  1414. X{
  1415. X    static char buf[100];
  1416. X    
  1417. X    if (lb->lb_type == ENDMARKER)
  1418. X        return "EMPTY";
  1419. X    else if (ISNONTERMINAL(lb->lb_type)) {
  1420. X        if (lb->lb_str == NULL) {
  1421. X            sprintf(buf, "NT%d", lb->lb_type);
  1422. X            return buf;
  1423. X        }
  1424. X        else
  1425. X            return lb->lb_str;
  1426. X    }
  1427. X    else {
  1428. X        if (lb->lb_str == NULL)
  1429. X            return tok_name[lb->lb_type];
  1430. X        else {
  1431. X            sprintf(buf, "%.32s(%.32s)",
  1432. X                tok_name[lb->lb_type], lb->lb_str);
  1433. X            return buf;
  1434. X        }
  1435. X    }
  1436. X}
  1437. EOF
  1438. fi
  1439. if test -s 'src/malloc.h'
  1440. then echo '*** I will not over-write existing file src/malloc.h'
  1441. else
  1442. echo 'x - src/malloc.h'
  1443. sed 's/^X//' > 'src/malloc.h' << 'EOF'
  1444. X/***********************************************************
  1445. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1446. XNetherlands.
  1447. X
  1448. X                        All Rights Reserved
  1449. X
  1450. XPermission to use, copy, modify, and distribute this software and its 
  1451. Xdocumentation for any purpose and without fee is hereby granted, 
  1452. Xprovided that the above copyright notice appear in all copies and that
  1453. Xboth that copyright notice and this permission notice appear in 
  1454. Xsupporting documentation, and that the names of Stichting Mathematisch
  1455. XCentrum or CWI not be used in advertising or publicity pertaining to
  1456. Xdistribution of the software without specific, written prior permission.
  1457. X
  1458. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1459. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1460. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1461. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1462. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1463. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1464. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1465. X
  1466. X******************************************************************/
  1467. X
  1468. X/* Lowest-level memory allocation interface */
  1469. X
  1470. X#ifdef THINK_C
  1471. X#define ANY void
  1472. X#ifndef THINK_C_3_0
  1473. X#define HAVE_STDLIB
  1474. X#endif
  1475. X#endif
  1476. X
  1477. X#ifdef __STD_C__
  1478. X#define ANY void
  1479. X#define HAVE_STDLIB
  1480. X#endif
  1481. X
  1482. X#ifndef ANY
  1483. X#define ANY char
  1484. X#endif
  1485. X
  1486. X#ifndef NULL
  1487. X#define NULL 0
  1488. X#endif
  1489. X
  1490. X#define NEW(type, n) ( (type *) malloc((n) * sizeof(type)) )
  1491. X#define RESIZE(p, type, n) \
  1492. X    if ((p) == NULL) \
  1493. X        (p) =  (type *) malloc((n) * sizeof(type)); \
  1494. X    else \
  1495. X        (p) = (type *) realloc((char *)(p), (n) * sizeof(type))
  1496. X#define DEL(p) free((char *)p)
  1497. X#define XDEL(p) if ((p) == NULL) ; else DEL(p)
  1498. X
  1499. X#ifdef HAVE_STDLIB
  1500. X#include <stdlib.h>
  1501. X#else
  1502. Xextern ANY *malloc PROTO((unsigned int));
  1503. Xextern ANY *calloc PROTO((unsigned int, unsigned int));
  1504. Xextern ANY *realloc PROTO((ANY *, unsigned int));
  1505. Xextern void free PROTO((ANY *)); /* XXX sometimes int on Unix old systems */
  1506. X#endif
  1507. EOF
  1508. fi
  1509. if test -s 'src/node.h'
  1510. then echo '*** I will not over-write existing file src/node.h'
  1511. else
  1512. echo 'x - src/node.h'
  1513. sed 's/^X//' > 'src/node.h' << 'EOF'
  1514. X/***********************************************************
  1515. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1516. XNetherlands.
  1517. X
  1518. X                        All Rights Reserved
  1519. X
  1520. XPermission to use, copy, modify, and distribute this software and its 
  1521. Xdocumentation for any purpose and without fee is hereby granted, 
  1522. Xprovided that the above copyright notice appear in all copies and that
  1523. Xboth that copyright notice and this permission notice appear in 
  1524. Xsupporting documentation, and that the names of Stichting Mathematisch
  1525. XCentrum or CWI not be used in advertising or publicity pertaining to
  1526. Xdistribution of the software without specific, written prior permission.
  1527. X
  1528. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1529. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1530. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1531. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1532. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1533. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1534. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1535. X
  1536. X******************************************************************/
  1537. X
  1538. X/* Parse tree node interface */
  1539. X
  1540. Xtypedef struct _node {
  1541. X    int        n_type;
  1542. X    char        *n_str;
  1543. X    int        n_lineno;
  1544. X    int        n_nchildren;
  1545. X    struct _node    *n_child;
  1546. X} node;
  1547. X
  1548. Xextern node *newtree PROTO((int type));
  1549. Xextern node *addchild PROTO((node *n, int type, char *str, int lineno));
  1550. Xextern void freetree PROTO((node *n));
  1551. X
  1552. X/* Node access functions */
  1553. X#define NCH(n)        ((n)->n_nchildren)
  1554. X#define CHILD(n, i)    (&(n)->n_child[i])
  1555. X#define TYPE(n)        ((n)->n_type)
  1556. X#define STR(n)        ((n)->n_str)
  1557. X
  1558. X/* Assert that the type of a node is what we expect */
  1559. X#ifndef DEBUG
  1560. X#define REQ(n, type) { /*pass*/ ; }
  1561. X#else
  1562. X#define REQ(n, type) \
  1563. X    { if (TYPE(n) != (type)) { \
  1564. X        fprintf(stderr, "FATAL: node type %d, required %d\n", \
  1565. X            TYPE(n), type); \
  1566. X        abort(); \
  1567. X    } }
  1568. X#endif
  1569. X
  1570. Xextern void listtree PROTO((node *));
  1571. Xextern void listnode PROTO((FILE *, node *));
  1572. EOF
  1573. fi
  1574. if test -s 'src/parser.h'
  1575. then echo '*** I will not over-write existing file src/parser.h'
  1576. else
  1577. echo 'x - src/parser.h'
  1578. sed 's/^X//' > 'src/parser.h' << 'EOF'
  1579. X/***********************************************************
  1580. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1581. XNetherlands.
  1582. X
  1583. X                        All Rights Reserved
  1584. X
  1585. XPermission to use, copy, modify, and distribute this software and its 
  1586. Xdocumentation for any purpose and without fee is hereby granted, 
  1587. Xprovided that the above copyright notice appear in all copies and that
  1588. Xboth that copyright notice and this permission notice appear in 
  1589. Xsupporting documentation, and that the names of Stichting Mathematisch
  1590. XCentrum or CWI not be used in advertising or publicity pertaining to
  1591. Xdistribution of the software without specific, written prior permission.
  1592. X
  1593. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1594. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1595. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1596. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1597. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1598. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1599. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1600. X
  1601. X******************************************************************/
  1602. X
  1603. X/* Parser interface */
  1604. X
  1605. X#define MAXSTACK 100
  1606. X
  1607. Xtypedef struct _stackentry {
  1608. X    int         s_state;    /* State in current DFA */
  1609. X    dfa        *s_dfa;        /* Current DFA */
  1610. X    struct _node    *s_parent;    /* Where to add next node */
  1611. X} stackentry;
  1612. X
  1613. Xtypedef struct _stack {
  1614. X    stackentry    *s_top;        /* Top entry */
  1615. X    stackentry     s_base[MAXSTACK];/* Array of stack entries */
  1616. X                    /* NB The stack grows down */
  1617. X} stack;
  1618. X
  1619. Xtypedef struct {
  1620. X    struct _stack     p_stack;    /* Stack of parser states */
  1621. X    struct _grammar    *p_grammar;    /* Grammar to use */
  1622. X    struct _node    *p_tree;    /* Top of parse tree */
  1623. X} parser_state;
  1624. X
  1625. Xparser_state *newparser PROTO((struct _grammar *g, int start));
  1626. Xvoid delparser PROTO((parser_state *ps));
  1627. Xint addtoken PROTO((parser_state *ps, int type, char *str, int lineno));
  1628. Xvoid addaccelerators PROTO((grammar *g));
  1629. EOF
  1630. fi
  1631. if test -s 'src/pgenheaders.h'
  1632. then echo '*** I will not over-write existing file src/pgenheaders.h'
  1633. else
  1634. echo 'x - src/pgenheaders.h'
  1635. sed 's/^X//' > 'src/pgenheaders.h' << 'EOF'
  1636. X/***********************************************************
  1637. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1638. XNetherlands.
  1639. X
  1640. X                        All Rights Reserved
  1641. X
  1642. XPermission to use, copy, modify, and distribute this software and its 
  1643. Xdocumentation for any purpose and without fee is hereby granted, 
  1644. Xprovided that the above copyright notice appear in all copies and that
  1645. Xboth that copyright notice and this permission notice appear in 
  1646. Xsupporting documentation, and that the names of Stichting Mathematisch
  1647. XCentrum or CWI not be used in advertising or publicity pertaining to
  1648. Xdistribution of the software without specific, written prior permission.
  1649. X
  1650. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1651. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1652. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1653. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1654. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1655. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1656. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1657. X
  1658. X******************************************************************/
  1659. X
  1660. X/* Include files and extern declarations used by most of the parser.
  1661. X   This is a precompiled header for THINK C. */
  1662. X
  1663. X#include <stdio.h>
  1664. X#include <string.h>
  1665. X
  1666. X#ifdef THINK_C
  1667. X/* #define THINK_C_3_0            /*** TURN THIS ON FOR THINK C 3.0 ****/
  1668. X#define label label_
  1669. X#undef label
  1670. X#endif
  1671. X
  1672. X#ifdef THINK_C_3_0
  1673. X#include <proto.h>
  1674. X#endif
  1675. X
  1676. X#ifdef THINK_C
  1677. X#ifndef THINK_C_3_0
  1678. X#include <stdlib.h>
  1679. X#endif
  1680. X#endif
  1681. X
  1682. X#include "PROTO.h"
  1683. X#include "malloc.h"
  1684. X
  1685. Xextern void fatal PROTO((char *));
  1686. EOF
  1687. fi
  1688. if test -s 'src/pythonrun.h'
  1689. then echo '*** I will not over-write existing file src/pythonrun.h'
  1690. else
  1691. echo 'x - src/pythonrun.h'
  1692. sed 's/^X//' > 'src/pythonrun.h' << 'EOF'
  1693. X/***********************************************************
  1694. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1695. XNetherlands.
  1696. X
  1697. X                        All Rights Reserved
  1698. X
  1699. XPermission to use, copy, modify, and distribute this software and its 
  1700. Xdocumentation for any purpose and without fee is hereby granted, 
  1701. Xprovided that the above copyright notice appear in all copies and that
  1702. Xboth that copyright notice and this permission notice appear in 
  1703. Xsupporting documentation, and that the names of Stichting Mathematisch
  1704. XCentrum or CWI not be used in advertising or publicity pertaining to
  1705. Xdistribution of the software without specific, written prior permission.
  1706. X
  1707. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1708. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1709. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1710. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1711. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1712. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1713. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1714. X
  1715. X******************************************************************/
  1716. X
  1717. X/* Interfaces to parse and execute pieces of python code */
  1718. X
  1719. Xvoid initall PROTO((void));
  1720. X
  1721. Xint run PROTO((FILE *, char *));
  1722. X
  1723. Xint run_script PROTO((FILE *, char *));
  1724. Xint run_tty_1 PROTO((FILE *, char *));
  1725. Xint run_tty_loop PROTO((FILE *, char *));
  1726. X
  1727. Xint parse_string PROTO((char *, int, struct _node **));
  1728. Xint parse_file PROTO((FILE *, char *, int, struct _node **));
  1729. X
  1730. Xobject *eval_node PROTO((struct _node *, char *, object *, object *));
  1731. X
  1732. Xobject *run_string PROTO((char *, int, object *, object *));
  1733. Xobject *run_file PROTO((FILE *, char *, int, object *, object *));
  1734. Xobject *run_err_node PROTO((int, struct _node *, char *, object *, object *));
  1735. Xobject *run_node PROTO((struct _node *, char *, object *, object *));
  1736. X
  1737. Xvoid print_error PROTO((void));
  1738. X
  1739. Xvoid goaway PROTO((int));
  1740. EOF
  1741. fi
  1742. if test -s 'src/regexp.h'
  1743. then echo '*** I will not over-write existing file src/regexp.h'
  1744. else
  1745. echo 'x - src/regexp.h'
  1746. sed 's/^X//' > 'src/regexp.h' << 'EOF'
  1747. X/***********************************************************
  1748. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1749. XNetherlands.
  1750. X
  1751. X                        All Rights Reserved
  1752. X
  1753. XPermission to use, copy, modify, and distribute this software and its 
  1754. Xdocumentation for any purpose and without fee is hereby granted, 
  1755. Xprovided that the above copyright notice appear in all copies and that
  1756. Xboth that copyright notice and this permission notice appear in 
  1757. Xsupporting documentation, and that the names of Stichting Mathematisch
  1758. XCentrum or CWI not be used in advertising or publicity pertaining to
  1759. Xdistribution of the software without specific, written prior permission.
  1760. X
  1761. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1762. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1763. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1764. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1765. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1766. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1767. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1768. X
  1769. X******************************************************************/
  1770. X
  1771. X/*
  1772. X * Definitions etc. for regexp(3) routines.
  1773. X *
  1774. X * Caveat:  this is V8 regexp(3) [actually, a reimplementation thereof],
  1775. X * not the System V one.
  1776. X */
  1777. X
  1778. X#define MULTILINE
  1779. X
  1780. X#define NSUBEXP  10
  1781. Xtypedef struct regexp {
  1782. X    char *startp[NSUBEXP];
  1783. X    char *endp[NSUBEXP];
  1784. X    char regstart;        /* Internal use only. */
  1785. X    char reganch;        /* Internal use only. */
  1786. X    char *regmust;        /* Internal use only. */
  1787. X    int regmlen;        /* Internal use only. */
  1788. X    char program[1];    /* Unwarranted chumminess with compiler. */
  1789. X} regexp;
  1790. X
  1791. Xextern regexp *regcomp();
  1792. Xextern int regexec();
  1793. X#ifdef MULTILINE
  1794. Xextern int reglexec();
  1795. X#endif
  1796. Xextern void regsub();
  1797. Xextern void regerror();
  1798. EOF
  1799. fi
  1800. if test -s 'src/sigtype.h'
  1801. then echo '*** I will not over-write existing file src/sigtype.h'
  1802. else
  1803. echo 'x - src/sigtype.h'
  1804. sed 's/^X//' > 'src/sigtype.h' << 'EOF'
  1805. X/***********************************************************
  1806. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1807. XNetherlands.
  1808. X
  1809. X                        All Rights Reserved
  1810. X
  1811. XPermission to use, copy, modify, and distribute this software and its 
  1812. Xdocumentation for any purpose and without fee is hereby granted, 
  1813. Xprovided that the above copyright notice appear in all copies and that
  1814. Xboth that copyright notice and this permission notice appear in 
  1815. Xsupporting documentation, and that the names of Stichting Mathematisch
  1816. XCentrum or CWI not be used in advertising or publicity pertaining to
  1817. Xdistribution of the software without specific, written prior permission.
  1818. X
  1819. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1820. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1821. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1822. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1823. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1824. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1825. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1826. X
  1827. X******************************************************************/
  1828. X
  1829. X/* The type of signal handlers is somewhat problematic.
  1830. X   This file encapsulates my knowledge about it:
  1831. X   - on the Mac (THINK C), it's int for 3.0, void for 4.0
  1832. X   - on other systems, it's usually void, except it's int on vax Ultrix.
  1833. X   Pass -DSIGTYPE=... to cc if you know better. */
  1834. X
  1835. X#ifndef SIGTYPE
  1836. X
  1837. X#ifdef THINK_C
  1838. X
  1839. X#ifdef THINK_C_3_0
  1840. X#define SIGTYPE int
  1841. X#else
  1842. X#define SIGTYPE void
  1843. X#endif
  1844. X
  1845. X#else /* !THINK_C */
  1846. X
  1847. X#if defined(vax) && !defined(AMOEBA)
  1848. X#define SIGTYPE int
  1849. X#else
  1850. X#define SIGTYPE void
  1851. X#endif
  1852. X
  1853. X#endif /* !THINK_C */
  1854. X
  1855. X#endif /* !SIGTYPE */
  1856. EOF
  1857. fi
  1858. if test -s 'src/token.h'
  1859. then echo '*** I will not over-write existing file src/token.h'
  1860. else
  1861. echo 'x - src/token.h'
  1862. sed 's/^X//' > 'src/token.h' << 'EOF'
  1863. X/***********************************************************
  1864. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1865. XNetherlands.
  1866. X
  1867. X                        All Rights Reserved
  1868. X
  1869. XPermission to use, copy, modify, and distribute this software and its 
  1870. Xdocumentation for any purpose and without fee is hereby granted, 
  1871. Xprovided that the above copyright notice appear in all copies and that
  1872. Xboth that copyright notice and this permission notice appear in 
  1873. Xsupporting documentation, and that the names of Stichting Mathematisch
  1874. XCentrum or CWI not be used in advertising or publicity pertaining to
  1875. Xdistribution of the software without specific, written prior permission.
  1876. X
  1877. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1878. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1879. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1880. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1881. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1882. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1883. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1884. X
  1885. X******************************************************************/
  1886. X
  1887. X/* Token types */
  1888. X
  1889. X#define ENDMARKER    0
  1890. X#define NAME        1
  1891. X#define NUMBER        2
  1892. X#define STRING        3
  1893. X#define NEWLINE        4
  1894. X#define INDENT        5
  1895. X#define DEDENT        6
  1896. X#define LPAR        7
  1897. X#define RPAR        8
  1898. X#define LSQB        9
  1899. X#define RSQB        10
  1900. X#define COLON        11
  1901. X#define COMMA        12
  1902. X#define SEMI        13
  1903. X#define PLUS        14
  1904. X#define MINUS        15
  1905. X#define STAR        16
  1906. X#define SLASH        17
  1907. X#define VBAR        18
  1908. X#define AMPER        19
  1909. X#define LESS        20
  1910. X#define GREATER        21
  1911. X#define EQUAL        22
  1912. X#define DOT        23
  1913. X#define PERCENT        24
  1914. X#define BACKQUOTE    25
  1915. X#define LBRACE        26
  1916. X#define RBRACE        27
  1917. X#define OP        28
  1918. X#define ERRORTOKEN    29
  1919. X#define N_TOKENS    30
  1920. X
  1921. X/* Special definitions for cooperation with parser */
  1922. X
  1923. X#define NT_OFFSET        256
  1924. X
  1925. X#define ISTERMINAL(x)        ((x) < NT_OFFSET)
  1926. X#define ISNONTERMINAL(x)    ((x) >= NT_OFFSET)
  1927. X#define ISEOF(x)        ((x) == ENDMARKER)
  1928. X
  1929. X
  1930. Xextern char *tok_name[]; /* Token names */
  1931. Xextern int tok_1char PROTO((int));
  1932. EOF
  1933. fi
  1934. if test -s 'src/typeobject.c'
  1935. then echo '*** I will not over-write existing file src/typeobject.c'
  1936. else
  1937. echo 'x - src/typeobject.c'
  1938. sed 's/^X//' > 'src/typeobject.c' << 'EOF'
  1939. X/***********************************************************
  1940. XCopyright 1991 by Stichting Mathematisch Centrum, Amsterdam, The
  1941. XNetherlands.
  1942. X
  1943. X                        All Rights Reserved
  1944. X
  1945. XPermission to use, copy, modify, and distribute this software and its 
  1946. Xdocumentation for any purpose and without fee is hereby granted, 
  1947. Xprovided that the above copyright notice appear in all copies and that
  1948. Xboth that copyright notice and this permission notice appear in 
  1949. Xsupporting documentation, and that the names of Stichting Mathematisch
  1950. XCentrum or CWI not be used in advertising or publicity pertaining to
  1951. Xdistribution of the software without specific, written prior permission.
  1952. X
  1953. XSTICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
  1954. XTHIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
  1955. XFITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
  1956. XFOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  1957. XWHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  1958. XACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
  1959. XOF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  1960. X
  1961. X******************************************************************/
  1962. X
  1963. X/* Type object implementation */
  1964. X
  1965. X#include "allobjects.h"
  1966. X
  1967. X/* Type object implementation */
  1968. X
  1969. Xstatic void
  1970. Xtype_print(v, fp, flags)
  1971. X    typeobject *v;
  1972. X    FILE *fp;
  1973. X    int flags;
  1974. X{
  1975. X    fprintf(fp, "<type '%s'>", v->tp_name);
  1976. X}
  1977. X
  1978. Xstatic object *
  1979. Xtype_repr(v)
  1980. X    typeobject *v;
  1981. X{
  1982. X    char buf[100];
  1983. X    sprintf(buf, "<type '%.80s'>", v->tp_name);
  1984. X    return newstringobject(buf);
  1985. X}
  1986. X
  1987. Xtypeobject Typetype = {
  1988. X    OB_HEAD_INIT(&Typetype)
  1989. X    0,            /* Number of items for varobject */
  1990. X    "type",            /* Name of this type */
  1991. X    sizeof(typeobject),    /* Basic object size */
  1992. X    0,            /* Item size for varobject */
  1993. X    0,            /*tp_dealloc*/
  1994. X    type_print,        /*tp_print*/
  1995. X    0,            /*tp_getattr*/
  1996. X    0,            /*tp_setattr*/
  1997. X    0,            /*tp_compare*/
  1998. X    type_repr,        /*tp_repr*/
  1999. X};
  2000. EOF
  2001. fi
  2002. echo 'Part 19 out of 21 of pack.out complete.'
  2003. exit 0
  2004.