Artifact ca4196c3cc2112620994dfdf87d205a8b3296806:
- File srfi/private/include.sls — part of check-in [80c8c83034] at 2016-07-07 18:11:39 on branch trunk — initial import (user: ovenpasta@pizzahack.eu size: 2106)
0000: 3b 3b 20 43 6f 70 79 72 69 67 68 74 20 28 63 29 ;; Copyright (c) 0010: 20 32 30 30 39 20 44 65 72 69 63 6b 20 45 64 64 2009 Derick Edd 0020: 69 6e 67 74 6f 6e 2e 20 20 41 6c 6c 20 72 69 67 ington. All rig 0030: 68 74 73 20 72 65 73 65 72 76 65 64 2e 0a 3b 3b hts reserved..;; 0040: 20 4c 69 63 65 6e 73 65 64 20 75 6e 64 65 72 20 Licensed under 0050: 61 6e 20 4d 49 54 2d 73 74 79 6c 65 20 6c 69 63 an MIT-style lic 0060: 65 6e 73 65 2e 20 20 4d 79 20 6c 69 63 65 6e 73 ense. My licens 0070: 65 20 69 73 20 69 6e 20 74 68 65 20 66 69 6c 65 e is in the file 0080: 0a 3b 3b 20 6e 61 6d 65 64 20 4c 49 43 45 4e 53 .;; named LICENS 0090: 45 20 66 72 6f 6d 20 74 68 65 20 6f 72 69 67 69 E from the origi 00a0: 6e 61 6c 20 63 6f 6c 6c 65 63 74 69 6f 6e 20 74 nal collection t 00b0: 68 69 73 20 66 69 6c 65 20 69 73 20 64 69 73 74 his file is dist 00c0: 72 69 62 75 74 65 64 0a 3b 3b 20 77 69 74 68 2e ributed.;; with. 00d0: 20 20 49 66 20 74 68 69 73 20 66 69 6c 65 20 69 If this file i 00e0: 73 20 72 65 64 69 73 74 72 69 62 75 74 65 64 20 s redistributed 00f0: 77 69 74 68 20 73 6f 6d 65 20 6f 74 68 65 72 20 with some other 0100: 63 6f 6c 6c 65 63 74 69 6f 6e 2c 20 6d 79 0a 3b collection, my.; 0110: 3b 20 6c 69 63 65 6e 73 65 20 6d 75 73 74 20 61 ; license must a 0120: 6c 73 6f 20 62 65 20 69 6e 63 6c 75 64 65 64 2e lso be included. 0130: 0a 0a 23 21 72 36 72 73 0a 28 6c 69 62 72 61 72 ..#!r6rs.(librar 0140: 79 20 28 73 72 66 69 20 70 72 69 76 61 74 65 20 y (srfi private 0150: 69 6e 63 6c 75 64 65 29 0a 20 20 28 65 78 70 6f include). (expo 0160: 72 74 20 0a 20 20 20 20 69 6e 63 6c 75 64 65 2f rt . include/ 0170: 72 65 73 6f 6c 76 65 29 0a 20 20 28 69 6d 70 6f resolve). (impo 0180: 72 74 20 0a 20 20 20 20 28 72 6e 72 73 29 20 0a rt . (rnrs) . 0190: 20 20 20 20 28 66 6f 72 20 28 73 72 66 69 20 70 (for (srfi p 01a0: 72 69 76 61 74 65 20 69 6e 63 6c 75 64 65 20 63 rivate include c 01b0: 6f 6d 70 61 74 29 20 65 78 70 61 6e 64 29 29 0a ompat) expand)). 01c0: 20 20 0a 20 20 28 64 65 66 69 6e 65 2d 73 79 6e . (define-syn 01d0: 74 61 78 20 69 6e 63 6c 75 64 65 2f 72 65 73 6f tax include/reso 01e0: 6c 76 65 0a 20 20 20 20 28 6c 61 6d 62 64 61 20 lve. (lambda 01f0: 28 73 74 78 29 0a 20 20 20 20 20 20 28 64 65 66 (stx). (def 0200: 69 6e 65 20 28 69 6e 63 6c 75 64 65 2f 6c 65 78 ine (include/lex 0210: 69 63 61 6c 2d 63 6f 6e 74 65 78 74 20 63 74 78 ical-context ctx 0220: 74 20 66 69 6c 65 6e 61 6d 65 29 0a 20 20 20 20 t filename). 0230: 20 20 20 20 28 77 69 74 68 2d 65 78 63 65 70 74 (with-except 0240: 69 6f 6e 2d 68 61 6e 64 6c 65 72 0a 20 20 20 20 ion-handler. 0250: 20 20 20 20 20 20 28 6c 61 6d 62 64 61 20 28 65 (lambda (e 0260: 78 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 28 x). ( 0270: 72 61 69 73 65 0a 20 20 20 20 20 20 20 20 20 20 raise. 0280: 20 20 20 28 63 6f 6e 64 69 74 69 6f 6e 0a 20 20 (condition. 0290: 20 20 20 20 20 20 20 20 20 20 20 20 28 6d 61 6b (mak 02a0: 65 2d 65 72 72 6f 72 29 0a 20 20 20 20 20 20 20 e-error). 02b0: 20 20 20 20 20 20 20 28 6d 61 6b 65 2d 77 68 6f (make-who 02c0: 2d 63 6f 6e 64 69 74 69 6f 6e 20 27 69 6e 63 6c -condition 'incl 02d0: 75 64 65 2f 72 65 73 6f 6c 76 65 29 0a 20 20 20 ude/resolve). 02e0: 20 20 20 20 20 20 20 20 20 20 20 28 6d 61 6b 65 (make 02f0: 2d 6d 65 73 73 61 67 65 2d 63 6f 6e 64 69 74 69 -message-conditi 0300: 6f 6e 20 22 65 72 72 6f 72 20 77 68 69 6c 65 20 on "error while 0310: 74 72 79 69 6e 67 20 74 6f 20 69 6e 63 6c 75 64 trying to includ 0320: 65 22 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 e"). 0330: 20 20 28 6d 61 6b 65 2d 69 72 72 69 74 61 6e 74 (make-irritant 0340: 73 2d 63 6f 6e 64 69 74 69 6f 6e 20 28 6c 69 73 s-condition (lis 0350: 74 20 66 69 6c 65 6e 61 6d 65 29 29 0a 20 20 20 t filename)). 0360: 20 20 20 20 20 20 20 20 20 20 20 28 69 66 20 28 (if ( 0370: 63 6f 6e 64 69 74 69 6f 6e 3f 20 65 78 29 20 65 condition? ex) e 0380: 78 20 28 6d 61 6b 65 2d 69 72 72 69 74 61 6e 74 x (make-irritant 0390: 73 2d 63 6f 6e 64 69 74 69 6f 6e 20 28 6c 69 73 s-condition (lis 03a0: 74 20 65 78 29 29 29 29 29 29 0a 20 20 20 20 20 t ex)))))). 03b0: 20 20 20 20 20 28 6c 61 6d 62 64 61 20 28 29 0a (lambda (). 03c0: 20 20 20 20 20 20 20 20 20 20 20 20 28 63 61 6c (cal 03d0: 6c 2d 77 69 74 68 2d 69 6e 70 75 74 2d 66 69 6c l-with-input-fil 03e0: 65 20 66 69 6c 65 6e 61 6d 65 0a 20 20 20 20 20 e filename. 03f0: 20 20 20 20 20 20 20 20 20 28 6c 61 6d 62 64 61 (lambda 0400: 20 28 66 69 70 29 0a 20 20 20 20 20 20 20 20 20 (fip). 0410: 20 20 20 20 20 20 20 28 6c 65 74 20 6c 6f 6f 70 (let loop 0420: 20 28 5b 61 20 27 28 29 5d 29 0a 20 20 20 20 20 ([a '()]). 0430: 20 20 20 20 20 20 20 20 20 20 20 20 20 28 6c 65 (le 0440: 74 20 28 5b 78 20 28 72 65 61 64 20 66 69 70 29 t ([x (read fip) 0450: 5d 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 ]). 0460: 20 20 20 20 20 20 20 28 69 66 20 28 65 6f 66 2d (if (eof- 0470: 6f 62 6a 65 63 74 3f 20 78 29 0a 20 20 20 20 20 object? x). 0480: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0490: 20 28 63 6f 6e 73 20 23 27 62 65 67 69 6e 20 28 (cons #'begin ( 04a0: 64 61 74 75 6d 2d 3e 73 79 6e 74 61 78 20 63 74 datum->syntax ct 04b0: 78 74 20 28 72 65 76 65 72 73 65 20 61 29 29 29 xt (reverse a))) 04c0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 . 04d0: 20 20 20 20 20 20 20 28 6c 6f 6f 70 20 28 63 6f (loop (co 04e0: 6e 73 20 78 20 61 29 29 29 29 29 29 29 29 29 29 ns x a)))))))))) 04f0: 0a 20 20 20 20 20 20 28 73 79 6e 74 61 78 2d 63 . (syntax-c 0500: 61 73 65 20 73 74 78 20 28 29 0a 20 20 20 20 20 ase stx (). 0510: 20 20 20 5b 28 63 74 78 74 20 28 6c 69 62 2d 70 [(ctxt (lib-p 0520: 61 74 68 2a 20 2e 2e 2e 29 20 66 69 6c 65 2d 70 ath* ...) file-p 0530: 61 74 68 29 0a 20 20 20 20 20 20 20 20 20 28 66 ath). (f 0540: 6f 72 2d 61 6c 6c 20 28 6c 61 6d 62 64 61 20 28 or-all (lambda ( 0550: 73 29 20 28 61 6e 64 20 28 73 74 72 69 6e 67 3f s) (and (string? 0560: 20 73 29 20 28 70 6f 73 69 74 69 76 65 3f 20 28 s) (positive? ( 0570: 73 74 72 69 6e 67 2d 6c 65 6e 67 74 68 20 73 29 string-length s) 0580: 29 29 29 20 0a 20 20 20 20 20 20 20 20 20 20 20 ))) . 0590: 20 20 20 20 20 20 20 28 73 79 6e 74 61 78 2d 3e (syntax-> 05a0: 64 61 74 75 6d 20 23 27 28 6c 69 62 2d 70 61 74 datum #'(lib-pat 05b0: 68 2a 20 2e 2e 2e 20 66 69 6c 65 2d 70 61 74 68 h* ... file-path 05c0: 29 29 29 0a 20 20 20 20 20 20 20 20 20 28 6c 65 ))). (le 05d0: 74 20 28 5b 70 20 28 61 70 70 6c 79 20 73 74 72 t ([p (apply str 05e0: 69 6e 67 2d 61 70 70 65 6e 64 20 0a 20 20 20 20 ing-append . 05f0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0600: 20 20 20 20 20 28 6d 61 70 20 28 6c 61 6d 62 64 (map (lambd 0610: 61 20 28 70 73 29 20 28 73 74 72 69 6e 67 2d 61 a (ps) (string-a 0620: 70 70 65 6e 64 20 22 2f 22 20 70 73 29 29 20 0a ppend "/" ps)) . 0630: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0640: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 28 73 (s 0650: 79 6e 74 61 78 2d 3e 64 61 74 75 6d 20 23 27 28 yntax->datum #'( 0660: 6c 69 62 2d 70 61 74 68 2a 20 2e 2e 2e 20 66 69 lib-path* ... fi 0670: 6c 65 2d 70 61 74 68 29 29 29 29 5d 0a 20 20 20 le-path))))]. 0680: 20 20 20 20 20 20 20 20 20 20 20 20 5b 73 70 20 [sp 0690: 28 73 65 61 72 63 68 2d 70 61 74 68 73 29 5d 29 (search-paths)]) 06a0: 0a 20 20 20 20 20 20 20 20 20 20 20 28 6c 65 74 . (let 06b0: 20 6c 6f 6f 70 20 28 5b 73 65 61 72 63 68 20 73 loop ([search s 06c0: 70 5d 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 p]). 06d0: 20 28 69 66 20 28 6e 75 6c 6c 3f 20 73 65 61 72 (if (null? sear 06e0: 63 68 29 0a 20 20 20 20 20 20 20 20 20 20 20 20 ch). 06f0: 20 20 20 28 65 72 72 6f 72 20 27 69 6e 63 6c 75 (error 'inclu 0700: 64 65 2f 72 65 73 6f 6c 76 65 20 22 63 61 6e 6e de/resolve "cann 0710: 6f 74 20 66 69 6e 64 20 66 69 6c 65 20 69 6e 20 ot find file in 0720: 73 65 61 72 63 68 20 70 61 74 68 73 22 0a 20 20 search paths". 0730: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 0740: 20 20 20 20 28 73 75 62 73 74 72 69 6e 67 20 70 (substring p 0750: 20 31 20 28 73 74 72 69 6e 67 2d 6c 65 6e 67 74 1 (string-lengt 0760: 68 20 70 29 29 20 73 70 29 0a 20 20 20 20 20 20 h p)) sp). 0770: 20 20 20 20 20 20 20 20 20 28 6c 65 74 20 28 5b (let ([ 0780: 66 75 6c 6c 20 28 73 74 72 69 6e 67 2d 61 70 70 full (string-app 0790: 65 6e 64 20 28 63 61 72 20 73 65 61 72 63 68 29 end (car search) 07a0: 20 70 29 5d 29 0a 20 20 20 20 20 20 20 20 20 20 p)]). 07b0: 20 20 20 20 20 20 20 28 69 66 20 28 66 69 6c 65 (if (file 07c0: 2d 65 78 69 73 74 73 3f 20 66 75 6c 6c 29 0a 20 -exists? full). 07d0: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 07e0: 20 20 28 69 6e 63 6c 75 64 65 2f 6c 65 78 69 63 (include/lexic 07f0: 61 6c 2d 63 6f 6e 74 65 78 74 20 23 27 63 74 78 al-context #'ctx 0800: 74 20 66 75 6c 6c 29 0a 20 20 20 20 20 20 20 20 t full). 0810: 20 20 20 20 20 20 20 20 20 20 20 28 6c 6f 6f 70 (loop 0820: 20 28 63 64 72 20 73 65 61 72 63 68 29 29 29 29 (cdr search)))) 0830: 29 29 29 5d 29 29 29 0a 29 0a )))]))).).