PennMUSH Community

Changeset 882

Show
Ignore:
Timestamp:
05/24/07 22:43:25 (1 year ago)
Author:
shawnw
Message:

expr: helper now does linting of help files

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • 1.8.3/branches/experimental/game/txt/helper/Makefile

    r877 r882  
    33CSCOPTS=-O2 
    44 
    5 helper: options.o entry.o read.o helper.o 
    6     csc -o helper $(CSCOPTS) options.o entry.o read.o helper.o 
     5helper: 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 
     8warnings.o: warnings.scm 
     9    csc -c $(CSCOPTS) warnings.scm 
    710 
    811options.o: options.scm 
  • 1.8.3/branches/experimental/game/txt/helper/README

    r877 r882  
    99(Assuming the pennmush/game/txt directory) 
    1010 
    11 helper/helper -f help.db init help.txt 
     11helper/helper [-f help.db] init help.txt 
    1212 
    13 Update a database after the help file changes: 
     13If you do not specify a database name, help.db is used. All following 
     14commands read a database specified by -f, or the default help.db. 
    1415 
    15 helper/helper -f help.db sync help.txt 
     16Once you have a help database, you can do the following: 
    1617 
    17 The -f option specifies the name of the database file. 
     18helper 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  
    22 
    33(declare 
     4 (unit helper:entry) 
    45 (fixnum) 
    56 (usual-integrations) 
    67 (disable-interrupts) 
    7  (unit helper:entry) 
    88 (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 
    1011      help-entries-save help-entries-load) 
    1112 (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?)) 
    1418 
    1519(define-constant he-file 1) 
     
    1721(define entry-version (apply bitwise-ior flags)) 
    1822 
     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 
    1936(define-record-type help-entry  
    20   (make-help-entry name aliases body
     37  (make-help-entry name aliases body xrefs
    2138  help-entry? 
    2239  (name help-entry-name) 
    2340  (aliases help-entry-aliases) 
    24   (body help-entry-body)) 
     41  (body help-entry-body help-entry-body!) 
     42  (xrefs help-entry-xrefs)) 
    2543 
    2644(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
    2846       (help-entry-name x) 
    2947       (help-entry-aliases x) 
    30        (help-entry-body x))) 
     48       (help-entry-body x) 
     49       (help-entry-xrefs x))) 
    3150 
    3251(define-reader-ctor 'help-entry make-help-entry) 
    33         
     52 
    3453; Write a help entry list to a file 
    3554(define (help-entries-save lst filename) 
     
    4564      (signal 'invalid-argument))) 
    4665 
     66(define (update-to-current vers data) data) 
     67 
    4768; Load a help entry list 
    4869(define (help-entries-load filename) 
     
    5172      (let ((version (read))) 
    5273    (cond 
    53      ((not (integer? version)) 
     74     ((not (can-use? version)) 
    5475      (signal 'invalid-file-format)) 
    5576     ((not (= version entry-version)) 
    5677      (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  
    22 (fixnum) 
    33 (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)) 
    58 
    69(require-extension srfi-37) 
    710 
    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")) 
    1114 
    1215 
     16(define help 
     17  (option 
     18   '(#\h "help") #f #f 
     19   (lambda (o n x vals) 
     20     (print #<<END 
     21Usage: 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. 
     30END 
     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  
    55 (unit helper:options) 
    66 (usual-integrations) 
    7  (export option option-set!) 
    8  (bound-to-procedure option option-get option-set!)) 
     7 (export option-get option-set!) 
     8 (bound-to-procedure real-option-get option-set!)) 
    99 
    1010(define options-tab 
    1111  '((tempate-directory . "helper/templates") 
     12    (warn-line-length . 78) 
    1213    (help-db . "help.db"))) 
    1314 
     
    2021    (signal 'no-such-option)))) 
    2122 
    22 (define (option-get name) 
     23(define (real-option-get name) 
    2324  (let ((val (assq name options-tab))) 
    2425    (if val (cdr val) (signal 'no-such-option)))) 
    2526 
    26 (define option (getter-with-setter option-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  
    44 (disable-interrupts) 
    55 (unit helper:read) 
    6  (uses helper:entry srfi-13
     6 (uses helper:entry srfi-13 helper:warnings
    77 (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)) 
    911 
    1012; Read a help file, return a list version 
    1113(define (read-help-file filename) 
    1214  (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))) 
    1325 
    1426; Really read a help file 
     
    2133       (current-aliases '()) 
    2234       (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)) 
    3658                    ; 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))))))) 
    6283 
    6384