Changeset 882
- Timestamp:
- 05/24/07 22:43:25 (1 year ago)
- Files:
-
- 1.8.3/branches/experimental/game/txt/helper/Makefile (modified) (1 diff)
- 1.8.3/branches/experimental/game/txt/helper/README (modified) (1 diff)
- 1.8.3/branches/experimental/game/txt/helper/entry.scm (modified) (4 diffs)
- 1.8.3/branches/experimental/game/txt/helper/helper.scm (modified) (1 diff)
- 1.8.3/branches/experimental/game/txt/helper/options.scm (modified) (2 diffs)
- 1.8.3/branches/experimental/game/txt/helper/read.scm (modified) (2 diffs)
- 1.8.3/branches/experimental/game/txt/helper/warnings.scm (added)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
1.8.3/branches/experimental/game/txt/helper/Makefile
r877 r882 3 3 CSCOPTS=-O2 4 4 5 helper: options.o entry.o read.o helper.o 6 csc -o helper $(CSCOPTS) options.o entry.o read.o helper.o 5 helper: options.o entry.o read.o warnings.o helper.o 6 csc -o helper options.o entry.o read.o warnings.o helper.o 7 8 warnings.o: warnings.scm 9 csc -c $(CSCOPTS) warnings.scm 7 10 8 11 options.o: options.scm 1.8.3/branches/experimental/game/txt/helper/README
r877 r882 9 9 (Assuming the pennmush/game/txt directory) 10 10 11 helper/helper -f help.dbinit help.txt11 helper/helper [-f help.db] init help.txt 12 12 13 Update a database after the help file changes: 13 If you do not specify a database name, help.db is used. All following 14 commands read a database specified by -f, or the default help.db. 14 15 15 helper/helper -f help.db sync help.txt 16 Once you have a help database, you can do the following: 16 17 17 The -f option specifies the name of the database file. 18 helper check 19 Scan the help files for possible issues. 20 Currently does the following tests: 21 22 * Cross-references: Warns about any See also: reference that 23 doesn't have a matching entry. 24 * Long lines: Warns about lines longer than --warn-line-lengths 25 characters (Default is 78). 26 * Duplicate names: Warns about duplicate entry names. 1.8.3/branches/experimental/game/txt/helper/entry.scm
r877 r882 2 2 3 3 (declare 4 (unit helper:entry) 4 5 (fixnum) 5 6 (usual-integrations) 6 7 (disable-interrupts) 7 (unit helper:entry)8 8 (export entry-version make-help-entry help-entry? help-entry-name 9 help-entry-aliases help-entry-body 9 help-entry-aliases help-entry-body help-entry-body! 10 help-entry-xrefs 10 11 help-entries-save help-entries-load) 11 12 (bound-to-procedure make-help-entry help-entry? help-entry-name 12 help-entry-liases help-entry-body 13 help-entries-save help-entries-load)) 13 help-entry-aliases help-entry-body help-entry-body! 14 help-entries-save help-entries-load 15 check-version supports can-use? 16 help-entry-xrefs) 17 (hide supports?)) 14 18 15 19 (define-constant he-file 1) … … 17 21 (define entry-version (apply bitwise-ior flags)) 18 22 23 (define minimum-flags (list he-file)) 24 (define minimum-version (apply bitwise-ior minimum-flags)) 25 26 27 (define (check-versions minvers vers2) 28 (= (bitwise-and minvers vers2) minvers)) 29 30 (define (can-use? vers) 31 (check-versions minimum-version vers)) 32 33 (define (supports? vers what) 34 (> (bitwise-ior vers he-file) 0)) 35 19 36 (define-record-type help-entry 20 (make-help-entry name aliases body )37 (make-help-entry name aliases body xrefs) 21 38 help-entry? 22 39 (name help-entry-name) 23 40 (aliases help-entry-aliases) 24 (body help-entry-body)) 41 (body help-entry-body help-entry-body!) 42 (xrefs help-entry-xrefs)) 25 43 26 44 (define-record-printer (help-entry x out) 27 (fprintf out "#,(help-entry ~S ~S ~S )"45 (fprintf out "#,(help-entry ~S ~S ~S ~S)~N" 28 46 (help-entry-name x) 29 47 (help-entry-aliases x) 30 (help-entry-body x))) 48 (help-entry-body x) 49 (help-entry-xrefs x))) 31 50 32 51 (define-reader-ctor 'help-entry make-help-entry) 33 52 34 53 ; Write a help entry list to a file 35 54 (define (help-entries-save lst filename) … … 45 64 (signal 'invalid-argument))) 46 65 66 (define (update-to-current vers data) data) 67 47 68 ; Load a help entry list 48 69 (define (help-entries-load filename) … … 51 72 (let ((version (read))) 52 73 (cond 53 ((not ( integer? version))74 ((not (can-use? version)) 54 75 (signal 'invalid-file-format)) 55 76 ((not (= version entry-version)) 56 77 (signal 'invalid-file-version)) 57 (let ((data (read))) 58 (if 59 (and (list? data) (not (null? data)) 60 (help-entry? (car data))) 61 data 62 (signal 'invalid-file-format)))))))) 78 (else 79 (let ((data (read))) 80 (if 81 (and (list? data) (not (null? data)) 82 (help-entry? (car data))) 83 (update-to-current version data) 84 (signal 'invalid-file-format))))))))) 1.8.3/branches/experimental/game/txt/helper/helper.scm
r877 r882 2 2 (fixnum) 3 3 (usual-integrations) 4 (uses helper:options helper:read helper:entry)) 4 (disable-interrupts) 5 (block) 6 (bound-to-procedure set-db-file help handle-op) 7 (uses helper:warnings helper:options helper:read helper:entry srfi-13)) 5 8 6 9 (require-extension srfi-37) 7 10 8 (let ((lst (read-help-file "help.txt")))9 (printf "The first topic in db is ~A\n" (help-entry-name (car lst)))10 (help-entries-save lst "help.db"))11 ;(let ((lst (read-help-file "help.txt"))) 12 ; (printf "The first topic in db is ~A\n" (help-entry-name (car lst))) 13 ; (help-entries-save lst "help.db")) 11 14 12 15 16 (define help 17 (option 18 '(#\h "help") #f #f 19 (lambda (o n x vals) 20 (print #<<END 21 Usage: helper [OPTIONS] CMD [ CMDARGS ] 22 23 OPTIONS: 24 -f HELPDB Set the help database file 25 --warn-line-length N The cutoff to warn about long lines in check. 26 27 COMMANDS: 28 init HELP.TXT Create a new help database 29 check Scan help entries for possible problems. 30 END 31 ) 32 (exit 0)))) 33 34 (define set-db-file 35 (option 36 '(#\f) #t #f 37 (lambda (o n filename vals) 38 (option-set! 'help-db filename) 39 '()))) 40 41 (define set-warn-line-length 42 (option 43 '("warn-line-length") #t #f 44 (lambda (o n len vals) 45 (option-set! 'warn-line-length (string->number len)) 46 '()))) 47 48 (define (load-help-db) 49 (help-entries-load (option-get 'help-db))) 50 51 (define (handle-init helpfile) 52 (let ((help-db (option-get 'help-db))) 53 (printf "Making new help database ~S from help file ~S.\n" 54 help-db helpfile) 55 (if (file-exists? help-db) (delete-file help-db)) 56 (help-entries-save (read-help-file helpfile) help-db))) 57 58 (define (handle-checks) 59 (let ((help-db (load-help-db))) 60 (check-warnings help-db))) 61 62 (define (commands cmd) 63 (if 64 (or (not (list? cmd)) (null? cmd)) 65 (error "Missing command. Use helper --help for usage.") 66 (let ((arglen (length (cdr cmd))) 67 (args (cdr cmd)) 68 (cmdname (car cmd))) 69 (cond 70 ((string-ci= cmdname "init") 71 (if (= arglen 1) 72 (handle-init (car args)) 73 (error "init expects a help file name"))) 74 ((string-ci= cmdname "check") 75 (handle-checks)) 76 (else 77 (error "unknown command name " cmdname)))))) 78 79 (handle-exceptions 80 exn 81 (begin 82 (switch exn 83 ('invalid-argument (display "error: invalid argument\n" 84 (current-error-port))) 85 ('invalid-file-format (fprintf (current-error-port) 86 "error: ~S is not a valid help db\n" 87 (option-get 'help-db))) 88 ('invalid-file-version (fprintf (current-error-port) 89 "error: ~S was created by an older version of this program and cannot be read.\n" 90 (option-get 'help-db))) 91 ('no-such-option (display "error: Attempted to use an invalid config option\n" 92 (current-error-port))) 93 ('parse-error (display "error: parse error in help file\n" 94 (current-error-port))) 95 (else (abort exn))) 96 (exit 1)) 97 (commands 98 (reverse (args-fold 99 (command-line-arguments) 100 (list help set-db-file set-warn-line-length) 101 (lambda (o n x vals) 102 (fprintf (current-error-port) "Unrecognized option ~A\n" n) 103 (exit 1)) 104 cons 105 '())))) 106 107 108 109 1.8.3/branches/experimental/game/txt/helper/options.scm
r877 r882 5 5 (unit helper:options) 6 6 (usual-integrations) 7 (export option option-set!)8 (bound-to-procedure optionoption-get option-set!))7 (export option-get option-set!) 8 (bound-to-procedure real-option-get option-set!)) 9 9 10 10 (define options-tab 11 11 '((tempate-directory . "helper/templates") 12 (warn-line-length . 78) 12 13 (help-db . "help.db"))) 13 14 … … 20 21 (signal 'no-such-option)))) 21 22 22 (define ( option-get name)23 (define (real-option-get name) 23 24 (let ((val (assq name options-tab))) 24 25 (if val (cdr val) (signal 'no-such-option)))) 25 26 26 (define option (getter-with-setteroption-get option-set!))27 (define option-get (getter-with-setter real-option-get option-set!)) 1.8.3/branches/experimental/game/txt/helper/read.scm
r877 r882 4 4 (disable-interrupts) 5 5 (unit helper:read) 6 (uses helper:entry srfi-13 )6 (uses helper:entry srfi-13 helper:warnings) 7 7 (export read-help-file) 8 (bound-to-procedure read-help-file do-read-help-file)) 8 (bound-to-procedure read-help-file do-read-help-file generate-entry 9 is-xref? parse-xref not-null? trim-empty-lines) 10 (hide not-null? trim-empty-lines)) 9 11 10 12 ; Read a help file, return a list version 11 13 (define (read-help-file filename) 12 14 (with-input-from-file filename do-read-help-file)) 15 16 ; Remove leading empty lines (Blank or all whitespace) from list 17 (define (trim-empty-lines lst) 18 (cond 19 ((null? lst) '()) 20 ((string-null? (string-trim-both (car lst))) 21 (trim-empty-lines (cdr lst))) 22 (else lst))) 23 24 (define (not-null? lst) (not (null? lst))) 13 25 14 26 ; Really read a help file … … 21 33 (current-aliases '()) 22 34 (current-body '())) 23 (let rep ((line (read-line))) 24 (cond 25 ((eof-object? line) 26 ; Return the list 27 (cons (make-help-entry current-name (sort current-aliases string<) 28 (reverse current-body)) so-far)) 29 ((and (eq? state 'in-body) (= (string-length line) 0)) 30 (set! current-body (cons "\n" current-body)) 31 (rep (read-line))) 32 ((= (string-length line) 0) 33 (rep (read-line))) 34 ((and (or (eq? state 'at-start) (eq? state 'in-body)) 35 (char=? (string-ref line 0) topic)) 35 (let 36 ((generate-entry 37 (lambda () 38 (let* ((aliases (sort current-aliases string<)) 39 (body1 (trim-empty-lines current-body)) 40 (xrefs (if (and (not-null? body1) 41 (is-xref? (car body1))) 42 (parse-xref (car body1)) 43 '())) 44 (body (reverse (if (not-null? xrefs) (cdr body1) body1)))) 45 (make-help-entry current-name aliases body xrefs))))) 46 (let rep ((line (read-line))) 47 (cond 48 ((eof-object? line) 49 ; Return the list 50 (cons (generate-entry) so-far)) 51 ((and (eq? state 'in-body) (= (string-length line) 0)) 52 (set! current-body (cons "\n" current-body)) 53 (rep (read-line))) 54 ((= (string-length line) 0) 55 (rep (read-line))) 56 ((and (or (eq? state 'at-start) (eq? state 'in-body)) 57 (char=? (string-ref line 0) topic)) 36 58 ; Start of new entry 37 (set! so-far (cons (make-help-entry current-name 38 (sort current-aliases string<) 39 (reverse current-body)) so-far)) 40 (set! current-name (string-trim (string-drop line 1))) 41 (set! current-body '()) 42 (set! current-aliases '()) 43 (set! state 'reading-aliases) 44 (rep (read-line))) 45 ((and (eq? state 'reading-aliases) 46 (char=? (string-ref line 0) topic)) 47 ; Another alias for the current entry 48 (set! current-aliases (cons (string-trim (string-drop line 1)) 49 current-aliases)) 50 (rep (read-line))) 51 ((and (eq? state 'reading-aliases) 52 (not (char=? (string-ref line 0) topic))) 53 ; First line of body 54 (set! state 'in-body) 55 (set! current-body (cons line current-body)) 56 (rep (read-line))) 57 ((eq? state 'in-body) 58 (set! current-body (cons line current-body)) 59 (rep (read-line))) 60 (else 61 (signal 'parse-error)))))) 59 (if (eq? state 'in-body) 60 (set! so-far (cons (generate-entry) so-far))) 61 (set! current-name (string-trim-both (string-drop line 1))) 62 (set! current-body '()) 63 (set! current-aliases '()) 64 (set! state 'reading-aliases) 65 (rep (read-line))) 66 ((and (eq? state 'reading-aliases) 67 (char=? (string-ref line 0) topic)) 68 ; Another alias for the current entry 69 (set! current-aliases (cons (string-trim-both (string-drop line 1)) 70 current-aliases)) 71 (rep (read-line))) 72 ((and (eq? state 'reading-aliases) 73 (not (char=? (string-ref line 0) topic))) 74 ; First line of body 75 (set! state 'in-body) 76 (set! current-body (cons line current-body)) 77 (rep (read-line))) 78 ((eq? state 'in-body) 79 (set! current-body (cons line current-body)) 80 (rep (read-line))) 81 (else 82 (signal 'parse-error))))))) 62 83 63 84
