1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667
|
; XDOC Documentation System for ACL2
; Copyright (C) 2009-2015 Centaur Technology
;
; Contact:
; Centaur Technology Formal Verification Group
; 7600-C N. Capital of Texas Highway, Suite 300, Austin, TX 78731, USA.
; http://www.centtech.com/
;
; License: (An MIT/X11-style license)
;
; Permission is hereby granted, free of charge, to any person obtaining a
; copy of this software and associated documentation files (the "Software"),
; to deal in the Software without restriction, including without limitation
; the rights to use, copy, modify, merge, publish, distribute, sublicense,
; and/or sell copies of the Software, and to permit persons to whom the
; Software is furnished to do so, subject to the following conditions:
;
; The above copyright notice and this permission notice shall be included in
; all copies or substantial portions of the Software.
;
; THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
; IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
; FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
; AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
; LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
; FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
; DEALINGS IN THE SOFTWARE.
;
; Original author: Jared Davis <jared@centtech.com>
; save-fancy.lisp
;
; Writes out the XDOC database into JSON format for the new, fancy viewer.
(in-package "XDOC")
(include-book "save-classic")
(include-book "importance")
(include-book "linkcheck")
(include-book "centaur/bridge/to-json" :dir :system)
(include-book "oslib/copy" :dir :system)
(include-book "centaur/misc/tshell" :dir :system)
(set-state-ok t)
(program)
(defun-inline json-encode-string (x acc)
(declare (type string x))
(cons #\" (bridge::json-encode-str x (cons #\" acc))))
(defun json-encode-filename (x acc)
(declare (type symbol x))
(json-encode-string
(str::rchars-to-string (file-name-mangle x nil))
acc))
(defun json-encode-filenames-aux (x acc)
(declare (xargs :guard (symbol-listp x)))
(b* (((when (atom x))
acc)
(acc (json-encode-filename (car x) acc))
((when (atom (cdr x)))
acc)
(acc (cons #\, acc)))
(json-encode-filenames-aux (cdr x) acc)))
(defun json-encode-filenames (x acc)
(declare (xargs :guard (symbol-listp x)))
(b* ((acc (cons #\[ acc))
(acc (json-encode-filenames-aux x acc)))
(cons #\] acc)))
#||
(str::rchars-to-string (json-encode-filename 'xdoc::foo nil))
(str::rchars-to-string (json-encode-filenames '(xdoc::a acl2::b str::c) nil))
||#
(defun json-encode-topicname (x base-pkg acc)
(declare (type symbol x)
(type symbol base-pkg))
(json-encode-string
(str::rchars-to-string (sym-mangle-cap x base-pkg nil nil))
acc))
(defun json-encode-topicnames-aux (x base-pkg acc)
(declare (xargs :guard (symbol-listp x)))
(b* (((when (atom x))
acc)
(acc (json-encode-topicname (car x) base-pkg acc))
((when (atom (cdr x)))
acc)
(acc (cons #\, acc)))
(json-encode-topicnames-aux (cdr x) base-pkg acc)))
(defun json-encode-topicnames (x base-pkg acc)
(declare (xargs :guard (symbol-listp x)))
(b* ((acc (cons #\[ acc))
(acc (json-encode-topicnames-aux x base-pkg acc)))
(cons #\] acc)))
#||
(str::rchars-to-string (json-encode-topicname 'xdoc::foo 'acl2::foo nil))
(str::rchars-to-string (json-encode-topicname 'xdoc::foo 'xdoc::bar nil))
(str::rchars-to-string (json-encode-topicnames '(acl2::sock-monster xdoc::shoe-monster)
'xdoc::bar nil))
||#
(defun json-encode-uid (x acc)
(declare (type integer x))
(if (< x 0)
(str::revappend-nat-to-dec-chars (- x) (cons #\- acc))
(str::revappend-nat-to-dec-chars x acc)))
(defun json-encode-uids-aux (x acc)
(declare (xargs :guard (integer-listp x)))
(b* (((when (atom x))
acc)
(acc (json-encode-uid (car x) acc))
((when (atom (cdr x)))
acc)
(acc (cons #\, acc)))
(json-encode-uids-aux (cdr x) acc)))
(defun json-encode-uids (x acc)
(declare (xargs :guard (integer-listp x)))
(b* ((acc (cons #\[ acc))
(acc (json-encode-uids-aux x acc)))
(cons #\] acc)))
#||
(str::rchars-to-string (json-encode-uids '() nil))
(str::rchars-to-string (json-encode-uids '(1 2 3) nil))
(str::rchars-to-string (json-encode-uids '(2 3 17 100) nil))
(str::rchars-to-string (json-encode-uids '(1 2 -3 -77) nil))
||#
(defun make-uid-map (n topics map)
(b* (((when (atom topics))
map)
(name1 (cdr (assoc :name (car topics))))
(map (hons-acons name1 n map)))
(make-uid-map (+ n 1) (cdr topics) map)))
(defun collect-uids (names uid-map)
;; Converts missing names into -1's.
(b* (((when (atom names))
nil)
(look (cdr (hons-get (car names) uid-map)))
((when look)
(cons (nfix look) (collect-uids (cdr names) uid-map))))
(cons -1 (collect-uids (cdr names) uid-map))))
; The basic idea here is to split the database into two files:
;
; - The INDEX will be an array containing sub-arrays with
; [key, name, parents, short, ...]
;
; - The DATA will bind KEY -> long
;
; Where the KEYs are just the "file names" in the old scheme. That is, they
; are nice, safe names that can be used in URLs or wherever.
;
; Why not just save it as one big table? The hope is that this kind of split
; will let us (in the web interface) load in the index and give the user a
; working display, even before the data has been loaded.
;
; As of July 2013, the serialized version of the xdoc table (before
; preprocessing, mind you) is 7.1 MB. The JSON-encoded, post-preprocessing
; (i.e., proper XML) version is over 22 MB. This doesn't count the additional
; documentation internal to Centaur or other companies. Even with fast
; internet connections, that can be a noticeable delay, and the size will only
; grow.
;
; We previously represented the XINDEX as a hash binding KEY -> [name, ...],
; but we now use an array instead and embed the key within it. The advantage
; of this new scheme is that it gives us an implicit way to refer to topics,
; viz., their position in the array. This seems like a useful capability for
; implementing search features.
(defun short-xml-for-topic (topic xtopic state)
;; Returns (mv xml-string state)
(b* ((short (or (cdr (assoc :short topic)) ""))
;; (base-pkg (cdr (assoc :base-pkg topic)))
(name (cdr (assoc :name topic)))
((xtopic xtopic))
;; ((mv short-rchars state)
;; (preprocess-main short name topics-fal nil base-pkg state nil))
;; (short-str (str::printtree->str short-rchars))
;; ((mv err &) (parse-xml short-str))
(err xtopic.short-err)
(short-str short)
(- (and err
(prog2$ (note-xdoc-error)
; See comment regarding the use of "; xdoc error" instead of "WARNING"
; in preprocess-topic (file prepare-topic.lisp).
(print-xdoc-error "~|~%; xdoc error: problem with :short in topic ~x0:~%~x1~%~%" (list name err)))))
(short-str-xml
(b* (((unless err)
short-str)
(tmp nil)
(tmp (str::printtree-rconcat
"<b><color rgb='#ff0000'>Markup error in :short</color></b>
<code>" tmp))
(tmp (simple-html-encode-str err 0 (length err) tmp))
(tmp (str::printtree-rconcat "</code>" tmp)))
(str::printtree->str tmp))))
(mv short-str-xml state)))
(defun long-xml-for-topic (topic xtopic state)
;; Returns (mv xml-string state)
(b* ((long (or (cdr (assoc :long topic)) ""))
;; (base-pkg (cdr (assoc :base-pkg topic)))
(name (cdr (assoc :name topic)))
((xtopic xtopic))
;; ((mv long-rchars state)
;; (preprocess-main long name topics-fal nil base-pkg state nil))
;; (long-str (str::printtree->str long-rchars))
;; ((mv err &) (parse-xml long-str))
(err xtopic.long-err)
(long-str long)
(-
(and err
(prog2$ (note-xdoc-error)
; See comment regarding the use of "; xdoc error" instead of "WARNING"
; in preprocess-topic (file prepare-topic.lisp).
(print-xdoc-error "~|~%; xdoc error: problem with :long in topic ~x0:~%~x1~%~%" (list name err)))))
(long-str-xml
(b* (((unless err)
long-str)
(tmp nil)
(tmp (str::printtree-rconcat
"<h3><color rgb='#ff0000'>Markup error in :long</color></h3>
<code>" tmp))
(tmp (simple-html-encode-str err 0 (length err) tmp))
(tmp (str::printtree-rconcat "</code>" tmp)))
(str::printtree->str tmp))))
(mv long-str-xml state)))
(defun json-encode-index-entry (topic topics xtopics-fal uid-map state acc)
(b* ((- (check-topic-syntax topic))
(name (cdr (assoc :name topic)))
(base-pkg (cdr (assoc :base-pkg topic)))
(parents (cdr (assoc :parents topic)))
(suborder0 (cdr (assoc :suborder topic)))
(suborder-flg (suborder-indicates-chronological-p suborder0))
(suborder (if suborder-flg
(apply-suborder suborder0
(find-children name topics t))
suborder0))
(parent-uids (collect-uids parents uid-map))
(suborder (and suborder (collect-uids suborder uid-map)))
(xtopic (cdr (hons-get name xtopics-fal)))
((mv short-str state) (short-xml-for-topic topic xtopic state))
; I originally used a JSON object like {"name":"Append","rawname":"..."} But
; then some back-of-the-napkin calculations said that these nice names were
; taking up about 400 KB of space in the index, so I figured I'd get rid of
; them and just use an array.
; IF YOU ADD/CHANGE THE ORDER THEN YOU MUST UPDATE XDOC.JS:
;; [key
(acc (cons #\[ acc))
(acc (json-encode-filename name acc))
; ,name (xml encoded nice topic name)
(acc (cons #\, acc))
(acc (json-encode-topicname name base-pkg acc))
; ,raw name (non-encoded symbol name, no package)
(acc (cons #\, acc))
(acc (json-encode-string (symbol-name name) acc))
; ,parent keys (array of keys for parents)
(acc (cons #\, acc))
(acc (json-encode-uids parent-uids acc))
; ,short: xml encoded short topic description
(acc (cons #\, acc))
(acc (json-encode-string short-str acc))
;; most topics don't have a suborder, so only include this if they do have one.
(acc (b* (((unless suborder)
acc)
(acc (cons #\, acc))
(acc (json-encode-uids suborder acc)))
acc))
(acc (cons #\] acc)))
(mv acc state)))
#||
(b* ((topics (get-xdoc-table (w state)))
(topics-fal (topics-fal topics))
(uid-map nil)
((mv acc state)
(json-encode-index-entry topics (car topics) topics-fal uid-map state nil))
(state (princ$ (str::rchars-to-string acc) *standard-co* state)))
state)
||#
(defun json-encode-index-aux (all-topics topics xtopics-fal uid-map state acc)
(b* (((when (atom topics))
(mv acc state))
((mv acc state) (json-encode-index-entry (car topics) all-topics xtopics-fal
uid-map state acc))
((when (atom (cdr topics)))
(mv acc state))
(acc (list* #\Space #\Newline #\, acc)))
(json-encode-index-aux all-topics (cdr topics) xtopics-fal uid-map state acc)))
(defun json-encode-index (topics0 topics xtopics-fal uid-map state acc)
; Topics is a version of topics0 that has been ordered. Topics0 preserves the
; order in which each topic was introduced into the xdoc table.
(b* ((acc (cons #\[ acc))
((mv acc state)
(json-encode-index-aux topics0 topics xtopics-fal uid-map state acc))
(acc (cons #\] acc)))
(mv acc state)))
#||
(b* ((topics (take 5 (get-xdoc-table (w state))))
(topics-fal (topics-fal topics))
((mv acc state)
(json-encode-index topics topics topics-fal state nil))
(state (princ$ (str::rchars-to-string acc) *standard-co* state)))
state)
||#
(defun json-encode-data-entry (topic xtopics-fal state acc)
(b* ((- (check-topic-syntax topic))
(name (cdr (assoc :name topic)))
(base-pkg (cdr (assoc :base-pkg topic)))
(parents (cdr (assoc :parents topic)))
(from (or (cdr (assoc :from topic)) "Unknown"))
(xtopic (cdr (hons-get name xtopics-fal)))
((mv long-str state) (long-xml-for-topic topic xtopic state))
(from-xml (str::rchars-to-string
(simple-html-encode-chars
(coerce from 'list) nil)))
(acc (json-encode-filename name acc))
(acc (str::revappend-chars ":[" acc))
; IF YOU ADD/CHANGE THE ORDER THEN YOU MUST UPDATE XDOC.JS:
; parent names (xml encoded nice parent names)
; BOZO move to xdata, probably
(acc (json-encode-topicnames parents base-pkg acc))
(acc (cons #\, acc))
(acc (json-encode-string from-xml acc))
(acc (cons #\, acc))
(acc (json-encode-string (symbol-package-name base-pkg) acc))
(acc (cons #\, acc))
(acc (json-encode-string long-str acc))
(acc (cons #\] acc)))
(mv acc state)))
#||
(b* ((topics (get-xdoc-table (w state)))
(topics-fal (topics-fal topics))
((mv acc state)
(json-encode-data-entry (car topics) topics-fal state nil))
(state (princ$ (str::rchars-to-string acc) *standard-co* state)))
state)
||#
(defun json-encode-data-aux (topics xtopics-fal state acc)
(b* (((when (atom topics))
(mv acc state))
((mv acc state) (json-encode-data-entry (car topics) xtopics-fal state acc))
((when (atom (cdr topics)))
(mv acc state))
(acc (list* #\Space #\Newline #\Newline #\, acc)))
(json-encode-data-aux (cdr topics) xtopics-fal state acc)))
(defun json-encode-data (topics xtopics-fal state acc)
(b* ((acc (cons #\{ acc))
((mv acc state) (json-encode-data-aux topics xtopics-fal state acc))
(acc (cons #\} acc)))
(mv acc state)))
#||
(b* ((topics (take 5 (get-xdoc-table (w state))))
(topics-fal (topics-fal topics))
(acc nil)
((mv acc state)
(json-encode-data topics topics-fal state acc))
(state (princ$ (str::rchars-to-string acc) *standard-co* state)))
state)
||#
(defun save-json-files (topics dir state)
(b* ((topics0 (force-missing-parents
(maybe-add-top-topic
(normalize-parents-list
(clean-topics topics)))))
(prev-event-table-binding
;; save the previous binding (or lack) of xdoc-get-event-table, set it
;; to one generated from the current world, and restore at the end
(and (acl2::f-boundp-global 'xdoc-get-event-table state)
(list (f-get-global 'xdoc-get-event-table state))))
(state (f-put-global 'xdoc-get-event-table (make-get-event*-table (w state) nil) state))
(topics-fal (time$ (topics-fal topics0)))
(- (cw "; Preprocessing ~x0 topics.~%" (len topics0)))
((mv preproc-topics state) (time$ (preprocess-transform-topics topics0 topics-fal state)
:msg "; Preprocessing: ~st sec, ~sa bytes.~%"))
(- (cw "; XML parsing preprocessed topics.~%"))
((mv xtopics state) (time$ (xtopics-from-topics preproc-topics state)
:msg "; XML parsing: ~st sec, ~sa bytes.~%"))
(- (cw "; Saving JSON files for ~x0 topics.~%" (len topics0)))
((mv ordered-topics ?sitemap state)
(time$ (order-topics-by-importance preproc-topics xtopics state)
:msg "; Importance sorting topics: ~st sec, ~sa bytes.~%"
:mintime 1/2))
;; (smfile (oslib::catpath dir "sitemap.xml"))
;; ((mv channel state) (open-output-channel smfile :character state))
;; (state (princ$ sitemap channel state))
;; (state (close-output-channel channel state))
(lcfile (oslib::catpath dir "linkcheck.html"))
((mv channel state) (open-output-channel lcfile :character state))
(state (princ$ (linkcheck xtopics) channel state))
(state (close-output-channel channel state))
; (topics-fal (time$ (topics-fal topics)))
(uid-map (time$ (make-uid-map 0 ordered-topics nil)))
(index nil)
(index (str::revappend-chars "var xindex = " index));
(xtopics-fal (time$ (xtopics-fal xtopics)))
((mv index state)
(time$ (json-encode-index preproc-topics ordered-topics xtopics-fal uid-map state index)
:msg "; Preparing JSON index: ~st sec, ~sa bytes.~%"))
(index (cons #\; index))
(index (str::rchars-to-string index))
(idxfile (oslib::catpath dir "xindex.js"))
((mv channel state) (open-output-channel idxfile :character state))
(state (princ$ index channel state))
(state (close-output-channel channel state))
(data nil)
(data (str::revappend-chars "var xdata = " data))
((mv data state)
(time$ (json-encode-data ordered-topics xtopics-fal state data)
:msg "; Preparing JSON topic data: ~st sec, ~sa bytes.~%"
:mintime 1/2))
(data (cons #\; data))
(data (str::rchars-to-string data))
(datafile (oslib::catpath dir "xdata.js"))
((mv channel state) (open-output-channel datafile :character state))
(state (princ$ data channel state))
(state (close-output-channel channel state))
(orphans (find-orphaned-topics topics topics-fal nil))
(- (fast-alist-free (@ xdoc-get-event-table)))
(state (if prev-event-table-binding
(f-put-global 'xdoc-get-event-table (car prev-event-table-binding) state)
(makunbound-global 'xdoc-get-event-table state))))
(or (not orphans)
(cw "~|~%WARNING: found topics with non-existent parents:~%~x0~%These ~
topics may only show up in the index pages.~%~%" orphans))
(fast-alist-free topics-fal)
(fast-alist-free uid-map)
state))
(defun copy-resource-dirs (resdir ;; path to new-manual/res
resource-dirs-alist ;; alist created by add-resource-directory
state)
(b* (((when (atom resource-dirs-alist))
state)
((cons dirname source-path) (car resource-dirs-alist))
(target-path (oslib::catpath resdir dirname))
(- (cw ";; Copying ~s0 --> ~s1.~%" source-path target-path))
(state (oslib::copy! source-path target-path :recursive t)))
(copy-resource-dirs resdir (cdr resource-dirs-alist) state)))
(defun prepare-fancy-dir (dir logo-image state)
(b* (((unless (stringp dir))
(er hard? 'prepare-fancy-dir "Dir must be a string, but is: ~x0.~%" dir)
state)
(dir-system (acl2::system-books-dir state))
(xdoc-dir (oslib::catpath dir-system "xdoc"))
(xdoc/fancy (oslib::catpath xdoc-dir "fancy"))
(- (cw "; Preparing directory ~s0.~%" dir))
(state (time$ (oslib::rmtree! dir)
:msg ";; Removing old directory: ~st sec, ~sa bytes.~%"))
(state (time$ (oslib::copy! xdoc/fancy dir :recursive t)
:msg ";; Copying xdoc/fancy files: ~st sec, ~sa bytes.~%"))
(state (if (not logo-image)
state
(time$ (b* ((dir/xdoc-logo.png (oslib::catpath dir "xdoc-logo.png"))
((mv error state)
(oslib::copy-file logo-image dir/xdoc-logo.png
:overwrite t))
((when error)
(er hard? 'prepare-fancy-dir
"Error copying logo image: ~@0" error)
state))
state)
:msg ";; Installing custom logo: ~st sec, ~sa bytes.~%")))
(- (cw "; Copying resource directories.~%"))
(resdir (oslib::catpath dir "res"))
(resource-dirs-alist (cdr (assoc 'resource-dirs (table-alist 'xdoc (w state)))))
(state (time$ (copy-resource-dirs resdir resource-dirs-alist state)
:msg ";; Copying resource directories: ~st sec, ~sa bytes.~%")))
state))
(defttag :xdoc) ; for sys-call+ call below
(defun run-fancy-zip (dir state)
(b* ((- (cw "; XDOC: Running zip.sh to create download/ directory.~%"))
;; We formerly used oslib::catpath here. However, David Rager reported
;; (2014-06-24) that this caused failures when using directories such as
;; "~/public_html", because the ~ doesn't get wildcard expanded in all
;; Lisps, e.g., CCL. So, we now use ACL2's extend-pathname, since it
;; gets rid of the ~ characters.
(dir-fix (acl2::extend-pathname dir "." state))
(zip.sh (acl2::extend-pathname dir-fix "zip.sh" state))
(cmd (string-append "sh "
(string-append zip.sh
(string-append " " dir-fix))))
((mv exit-status lines state)
(time$ (acl2::tshell-call cmd :print t)
:msg "; XDOC zip.sh: ~st sec, ~sa bytes.~%"))
((unless (equal exit-status 0))
(acl2::warning$ 'run-fancy-zip "run-fancy-zip"
"zip.sh failed to create a zip file for directory ~x0 ~
(exit code ~x1). ~x2."
dir-fix exit-status lines)))
state))
; The check done by check-xdoc-topics (and addition of functions below to
; support it) was added by Matt K. in November 2019, to ease debugging of the
; case that a non-standard character in the :long string can cause there to be
; an empty page in the web-based manual. (This actually happened when a stray
; control-P wound up in the documentation for defstobj.) Note that this check
; is probably not complete, for example since preprocessing has not yet been
; applied to the given topics. Rather than try to get a clearer understanding
; of the generation of web pages from xdoc source, I'm taking this conservative
; approach. Our first implementation did not allow tabs, but that uncovered 23
; violations in the acl2+books manual, so for now at least we'll allow tabs.
(defun standard+-string-p1 (x n)
; Based on standard-string-p1 in the ACL2 source code.
(declare (xargs :guard (and (stringp x)
(natp n)
(<= n (length x)))))
(cond ((zp n) t)
(t (let ((n (1- n)))
(and (or (standard-char-p (char x n))
(eql (char x n) #\Tab))
(standard+-string-p1 x n))))))
(defun standard+-string-p (x)
(declare (xargs :guard (stringp x)))
(standard+-string-p1 x (length x)))
(defun non-standard+-char-position1 (x n)
; Based on standard-string-p1 in the ACL2 source code.
(declare (xargs :guard (and (stringp x)
(natp n)
(<= n (length x)))))
(cond ((zp n) nil)
(t (let ((n (1- n)))
(if (or (standard-char-p (char x n))
(eql x #\Tab))
(non-standard+-char-position1 x n)
n)))))
(defun non-standard+-char-position (x)
(declare (xargs :guard (stringp x)))
(non-standard+-char-position1 x (length x)))
(defun check-xdoc-topics (topics msg-list)
(cond
((endp topics)
(cond
(msg-list (xdoc-error "~*1"
'check-xdoc-topics
`("impossible" ; when nothing to print
"~@*." ; the last element
"~@*; and~|~%" ; the 2nd to last element
"~@*;~|~%" ; all other elements
,msg-list)))
(t nil)))
(t
(check-xdoc-topics
(cdr topics)
(let* ((topic (car topics))
(ap (alistp (car topics)))
(short (and ap (cdr (assoc-eq :short topic))))
(long (and ap (cdr (assoc-eq :long topic)))))
(cond
((not ap) ; impossible?
(cons (msg "Topic is not an alist: ~x0"
topic)
msg-list))
(t
(let* ((msg-list
(cond
((and short
(not (standard+-string-p short)))
(let ((posn (non-standard+-char-position short)))
(cons (msg "Found non-standard character, ~x0, in the ~
:short string of the topic named ~x1, at ~
position ~x2"
(char short posn)
(cdr (assoc-eq :name topic))
posn)
msg-list)))
(t msg-list)))
(msg-list
(cond
((and long
(not (standard+-string-p long)))
(let ((posn (non-standard+-char-position long)))
(cons (msg "Found non-standard character, ~x0, in the ~
:long string of the topic named ~x1, at ~
position ~x2"
(char long posn)
(cdr (assoc-eq :name topic))
posn)
msg-list)))
(t msg-list))))
msg-list))))))))
(defun save-fancy (all-topics dir zip-p logo-image broken-links-limit state)
(prog2$
(check-xdoc-topics all-topics nil)
(b* ((state (f-put-global 'broken-links-limit broken-links-limit state))
(state (prepare-fancy-dir dir logo-image state))
(state (save-json-files all-topics dir state))
(state (if zip-p
(run-fancy-zip dir state)
state)))
state)))
|