;; TOC = Table of Contents. ;; Emacs-Time-stamp: "2007-11-22 09:48:41" (setq file-stamp "Emacs-File-stamp: \"/home/ysverdlov/leninist.biz/lb-toc.el\"") ;;; ======================================================= ;; ~/leninist.biz/en/1973/WICIR313/index.tab ;; (setq arg1drctn "PREV") ;; (setq arg2up9 "UP0" ) ;; (setq arg3lbg-i-from1 3 ) ;; --------------------------------- ;; (lb-ht-get-adjacent "PREV" "UP0" 1) => nil ;; (lb-ht-get-adjacent "NEXT" "UP0" 1) => 2 ;; (lb-ht-get-adjacent "PREV" "UP0" 2) => 1 ;; (lb-ht-get-adjacent "NEXT" "UP0" 2) => 3 ;; (lb-ht-get-adjacent "PREV" "UP0" 3) => nil ...nothing before intro. ;; (lb-ht-get-adjacent "NEXT" "UP0" 3) => 4 ;; (lb-ht-get-adjacent "PREV" "UP0" 4) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP0" 4) => 5 ;; (lb-ht-get-adjacent "PREV" "UP0" 5) => nil ...first LVL3. ;; (lb-ht-get-adjacent "NEXT" "UP0" 5) => 6 ;; (lb-ht-get-adjacent "PREV" "UP0" 6) => 5 ;; (lb-ht-get-adjacent "NEXT" "UP0" 6) => 7 ;; (lb-ht-get-adjacent "PREV" "UP0" 7) => 6 ;; (lb-ht-get-adjacent "NEXT" "UP0" 7) => nil ;; (lb-ht-get-adjacent "PREV" "UP0" 8) => 5 ;; (lb-ht-get-adjacent "NEXT" "UP0" 8) => nil ;; (lb-ht-get-adjacent "PREV" "UP0" 9) => nil ;; (lb-ht-get-adjacent "NEXT" "UP0" 9) => 10 ;; (lb-ht-get-adjacent "PREV" "UP0" 10) => nil ...start of 2nd LVL3 group. ;; (lb-ht-get-adjacent "NEXT" "UP0" 10) => 11 ;; (lb-ht-get-adjacent "PREV" "UP0" 11) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP0" 11) => 12 ;; (lb-ht-get-adjacent "PREV" "UP0" 12) => 11 ;; (lb-ht-get-adjacent "NEXT" "UP0" 12) => nil ;; (lb-ht-get-adjacent "PREV" "UP0" 13) => nil ;; (lb-ht-get-adjacent "NEXT" "UP0" 13) => 14 ;; (lb-ht-get-adjacent "PREV" "UP0" 14) => 13 ;; (lb-ht-get-adjacent "NEXT" "UP0" 14) => 15 ;; (lb-ht-get-adjacent "PREV" "UP0" 15) => 14 ;; (lb-ht-get-adjacent "NEXT" "UP0" 15) => 16 ;; (lb-ht-get-adjacent "PREV" "UP0" 16) => 15 ;; (lb-ht-get-adjacent "NEXT" "UP0" 16) => nil ;; --------------------------------- ;; (lb-ht-get-adjacent "PREV" "UP1" 1) => nil ;; (lb-ht-get-adjacent "NEXT" "UP1" 1) => nil ;; (lb-ht-get-adjacent "PREV" "UP1" 2) => nil ;; (lb-ht-get-adjacent "NEXT" "UP1" 2) => nil ;; (lb-ht-get-adjacent "PREV" "UP1" 3) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP1" 3) => 9 ;; (lb-ht-get-adjacent "PREV" "UP1" 4) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP1" 4) => 9 ;; (lb-ht-get-adjacent "PREV" "UP1" 5) => 4 ;; (lb-ht-get-adjacent "NEXT" "UP1" 5) => 8 ;; (lb-ht-get-adjacent "PREV" "UP1" 6) => 4 ;; (lb-ht-get-adjacent "NEXT" "UP1" 6) => 8 ;; (lb-ht-get-adjacent "PREV" "UP1" 7) => 4 ;; (lb-ht-get-adjacent "NEXT" "UP1" 7) => 8 ;; (lb-ht-get-adjacent "PREV" "UP1" 8) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP1" 8) => 9 ;; (lb-ht-get-adjacent "PREV" "UP1" 9) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP1" 9) => 17 ;; (lb-ht-get-adjacent "PREV" "UP1" 10) => 9 ;; (lb-ht-get-adjacent "NEXT" "UP1" 10) => 13 ;; (lb-ht-get-adjacent "PREV" "UP1" 11) => 9 ;; (lb-ht-get-adjacent "NEXT" "UP1" 11) => 13 ;; (lb-ht-get-adjacent "PREV" "UP1" 12) => 9 ;; (lb-ht-get-adjacent "NEXT" "UP1" 12) => 13 ;; (lb-ht-get-adjacent "PREV" "UP1" 13) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP1" 13) => 17 ;; (lb-ht-get-adjacent "PREV" "UP1" 14) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP1" 14) => 17 ;; (lb-ht-get-adjacent "PREV" "UP1" 15) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP1" 15) => 17 ;; (lb-ht-get-adjacent "PREV" "UP1" 16) => 10 ;; (lb-ht-get-adjacent "NEXT" "UP1" 16) => 17 ;; --------------------------------- ;; (lb-ht-get-adjacent "PREV" "UP2" 1) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 1) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 2) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 2) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 3) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 3) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 4) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 4) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 5) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP2" 5) => 9 ;; (lb-ht-get-adjacent "PREV" "UP2" 6) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP2" 6) => 9 ;; (lb-ht-get-adjacent "PREV" "UP2" 7) => 2 ;; (lb-ht-get-adjacent "NEXT" "UP2" 7) => 9 ;; (lb-ht-get-adjacent "PREV" "UP2" 8) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 8) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 9) => nil ;; (lb-ht-get-adjacent "NEXT" "UP2" 9) => nil ;; (lb-ht-get-adjacent "PREV" "UP2" 10) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 10) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 11) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 11) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 12) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 12) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 13) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 13) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 14) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 14) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 15) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 15) => 17 ;; (lb-ht-get-adjacent "PREV" "UP2" 16) => 3 ;; (lb-ht-get-adjacent "NEXT" "UP2" 16) => 17 ;;; ======================================================= ;; ~/leninist.biz/en/1976/GPSPW3PP/index.tab ;; (setq arg1drctn "NEXT") ;; (setq arg2up9 "UP0" ) ;; (setq arg3lbg-i-from1 30 ) ;; --------------------------------- ;; (lb-ht-get-adjacent "PREV" "UP1" 28) ;; (lb-ht-get-adjacent "NEXT" "UP1" 28) ;; (lb-ht-get-adjacent "PREV" "UP0" 30) ;; (lb-ht-get-adjacent "NEXT" "UP0" 30) ;; (defun lb-ht-get-adjacent (arg1drctn arg2up9 arg3lbg-i-from1) "Called by lb-ht-common-__. ARG1 is 'PREV' or 'NEXT'. ARG2 is 'UP0' or 'UP1' or 'UP2'. ARG3 is lbg-i-from1 (may be able to do without this ARG). Returns list with three items: 1. integer of section located (1-based), 2. cons pointing to desired NUMERIC and ALPHA within section (nth), 3. section located as a list with 6 members" ;; (_-dfun-hook "lb-ht-get-adjacent") ;; (let (lb-arg2up9-int lb-volunteer-ARG3 lb-lowest-lvl-here lb-drctn-offset lb-candidate lb-rc-i lb-lowest-numeric-for-nth-function lb-lowest-alpha-for-nth-function lb-set-rc-flag lb-cnt-2-2 lb-rc) ;; fix! ;; file:///home/login/leninist.biz/en/1973/WICIR313/CHAPTER-IV ;; After using ">>" for going from "CHAPTER IV" to "Conclusion", ;; "<<" does *NOT* point back to "CHAPTER IV" but "<" does! ;; fix? ;; When would it error? Never? Input values probably controlled. ;; NOTE: BELOW: 1st call of (lb-ht-toc-get-headings : ARG3 is nil. ;; NOTE: BELOW: 2nd call of (lb-ht-toc-get-headings : ARG3 is t. ;; NOTE: BELOW: 3rd call of (lb-ht-toc-get-headings : ARG3 is t. (if (< arg3lbg-i-from1 1) (error "%s: %s" "too small" (prin1-to-string arg3lbg-i-from1)) (if (> arg3lbg-i-from1 (1- (length lbg-sections))) (error "%s: %s" "too big" (prin1-to-string arg3lbg-i-from1)))) (progn ;; GLOBALS. (setq lb-arg2up9-int (_-string-to-int arg2up9)) ;; (setq lb-volunteer-ARG3 (lb-ht-toc-get-headings arg3lbg-i-from1 nil ;; very important! nil )) ;; How far down? UP0 is possible with LVL1, 2 and 3. ;; How far down? UP1 is possible with LVL2 and 3. ;; How far down? UP2 is possible with LVL3. (setq lb-lowest-lvl-here (cond ((or (nth 5 lb-volunteer-ARG3) (nth 4 lb-volunteer-ARG3)) 3) ((or (nth 3 lb-volunteer-ARG3) (nth 2 lb-volunteer-ARG3)) 2) ((or (nth 1 lb-volunteer-ARG3) (nth 0 lb-volunteer-ARG3)) 1))) ;; Pointers into candidate pointing to lowest level. ;; If 3 down, use nth 4 (NUMERIC) and 5 (ALPHA). ;; If 2 down, use nth 2 (NUMERIC) and 3 (ALPHA). ;; If 1 down, use nth 0 (NUMERIC) and 1 (ALPHA). (setq lb-lowest-alpha-for-nth-function (1+ (setq lb-lowest-numeric-for-nth-function ;; (+ -2 (* 2 1)) => 0 ;; (+ -2 (* 2 2)) => 2 ;; (+ -2 (* 2 3)) => 4 (+ -2 (* 2 lb-lowest-lvl-here))))) ;; (setq lb-drctn-offset (if (string= "PREV" arg1drctn) -1 (if (string= "NEXT" arg1drctn) +1 (error "%s: %s" "Invalid choice" arg1drctn)))) ;; (cond ;; lb-cnt-2-2 ((= lb-arg2up9-int 0) ;; UP0 ;; Always take first one. (setq lb-cnt-2-2 1)) ((and ;; UP1 and UP2. (>= lb-arg2up9-int 1) ;; 3 - 1 = is GE 1. ;; 3 - 2 = is GE 1. ;; 2 - 1 = is GE 1. ;; 2 - 2 = is not GE 1. If at LVL2, cannot go up 2 levels. ;; 1 - 1 = is not GE 1. If at LVL1, cannot go up. ;; 1 - 2 = is not GE 1. If at LVL1, cannot go up. (>= (- lb-lowest-lvl-here lb-arg2up9-int) 1) ;; Where to find a non-nil UP-cell? ;; If looking L, ... 1 or 2 non-nil hops? (if (= -1 lb-drctn-offset) ;; ... if this one is non-nil at the UP-level, count it. ;; (Take second available cell, this one included.) (or (nth (- lb-lowest-numeric-for-nth-function (* 2 lb-arg2up9-int)) lb-volunteer-ARG3) (nth (- lb-lowest-alpha-for-nth-function (* 2 lb-arg2up9-int)) lb-volunteer-ARG3)) ;; If looking R, ... always one non-nil hop. ;; ... if this one is nil at the UP-level, count it. ;; ... if this one is non-nil at the UP-level, count it. ;; (Take first available cell to the right.) ;; (Contents of this cell at UP-level does not matter.) t)) (setq lb-cnt-2-2 1)) (t ;; DEFAULT (setq lb-cnt-2-2 0))) ;; ------------------------------------------------------- ;; FEEDBACK when testing containing PROGN. (list (list (cons arg1drctn lb-drctn-offset) (cons arg2up9 lb-arg2up9-int) arg3lbg-i-from1) (if (/= lb-lowest-lvl-here (string-to-int (nth 1 (assoc arg3lbg-i-from1 lbg-sections-max-levels-list)))) (error "%s: %s" "CHECK" "lbg-sections-max-levels-list") lb-lowest-lvl-here) (list lb-lowest-numeric-for-nth-function lb-lowest-alpha-for-nth-function) lb-cnt-2-2 lb-volunteer-ARG3)) ;;; ^ FEEDBACK (when ;; Loop or not to loop? (and ;; ------------------------------------------------------- ;; If at lb-lowest-lvl-here= LVL3, "UP0" "UP1" "UP2" valid. ;; If at lb-lowest-lvl-here= LVL2, "UP0" "UP1" valid. ;; If at lb-lowest-lvl-here= LVL1, "UP0" valid. ;; If at lb-lowest-lvl-here= LVL1, "UP1" and "UP2" invalid. ;; If at lb-lowest-lvl-here= LVL2, "UP2" invalid. (> lb-lowest-lvl-here lb-arg2up9-int) ;; ------------------------------------------------------- ) ;; Loop or not to loop? (loop for lb-i from ;; Start with looking backward one (-1) or forward one (1). 1 to ;; Approx. number of potential hops: a bit more than possible. (1+ (length lbg-sections)) do (if ;; This "if" first thing after "do" of "loop". (or ;; Reasons to BREAK. --------------------------------- ;; ------------------------------------------------------- ;; ------------------------------------------------------- ;; BREAK if t. ----- Nothing available. (not (setq lb-candidate (lb-ht-toc-get-headings (setq lb-rc-i (+ arg3lbg-i-from1 (* lb-i lb-drctn-offset))) nil ;; very important! t ;; very important! )) ) ;; ------------------------------------------------------- ;; BREAK if t. ----- UP0 test. ;; Lateral search (left or right sibling) at lowest level. (and (string= "UP0" arg2up9) (>= lb-lowest-lvl-here 2) ;; Able to look UP one. (if (= -1 lb-drctn-offset) ;; Looking L. ;; Do not use L sibling if parent of this one is non-nil. (or (nth (- lb-lowest-numeric-for-nth-function 2) lb-volunteer-ARG3) (nth (- lb-lowest-alpha-for-nth-function 2) lb-volunteer-ARG3)) ;; DO NOT SEPARATE! (if (= 1 lb-drctn-offset) ;; ;; Looking R. ;; Do not use R sibling if parent of R sibling is non-nil. (or (nth (- lb-lowest-numeric-for-nth-function 2) lb-candidate) (nth (- lb-lowest-alpha-for-nth-function 2) lb-candidate))) ) ;; ------------------------------------------------------- ;; BREAK if t. ----- At LVL3 looking UP1 test to the RIGHT. ;; NOTE: Same test to the LEFT is done at VERY END. (and (string= "UP1" arg2up9) ;; LVL3 ONLY. (= 3 lb-lowest-lvl-here) ;; LOOKING RIGHT ONLY. (= 1 lb-drctn-offset) ;; Anything at LVL1 should act as a block. (or (nth 0 lb-candidate) (nth 1 lb-candidate)) ) ;; ------------------------------------------------------- ) ;; Reasons to BREAK. --------------------------------- ;; BREAK: (setq lb-i 99999) ;; ------------------------------------------------------- ;; No brakes. Maybe use this one. ;; ------------------------------------------------------- ;; ~/leninist.biz/en/1973/WICIR313/index.tab ;; 1 2 ;; 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 ;; x x x x x ;; x x x x x x x x ;; x x x x x x x x x x ;; ;; A i I II III ;; i 1 2 3 i 1 2 i ;; i D C i C I i A A F ;; ------------------------------------------------------- ;; ~/leninist.biz/en/1987/WDM326/index.tab ;; ;; BUG: (6.)(2.)(a) had a left UP0 sibling of (3.)(1.)(c) !!! ;; 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 ;; x x x x x x ;; x x x x x x x x x x x x x x x x x x x x x x x x x ;; x x x x ;; ;; F 1 2 3 4 5 ;; 1 2 3 4 5 1 2 3 4 5 6 1 2 3 i 1 2 3 4 i 1 2 3 4 5 ;; i a b c ;; ;; ------------------------------------------------------- (when ;; Found one? (and (or (nth (- lb-lowest-numeric-for-nth-function (* 2 lb-arg2up9-int)) lb-candidate) (nth (- lb-lowest-alpha-for-nth-function (* 2 lb-arg2up9-int)) lb-candidate)) (setq lb-cnt-2-2 (1+ lb-cnt-2-2))) ;; (when (= 2 lb-cnt-2-2) (setq lb-rc (list lb-rc-i (cons lb-lowest-numeric-for-nth-function lb-lowest-alpha-for-nth-function) lb-candidate)) (setq lb-i 99999)) ;; ;; ------------------------------------------------------- ;; BREAK if t. ----- At LVL3 looking UP1 test to the LEFT. (if (and (string= "UP1" arg2up9) ;; LVL3 ONLY. (= 3 lb-lowest-lvl-here) ;; LOOKING LEFT ONLY. (= -1 lb-drctn-offset) ;; Anything at LVL1 should act as a block. (or (nth 0 lb-candidate) (nth 1 lb-candidate)) ) (setq lb-i 99999)) ) ) ) ) lb-rc)) ;; (lb-ht-toc-table-force-two-td) (defun lb-ht-toc-table-force-two-td nil "An alpha-lvl-1 like CHAPTER I may be squeezed into first column where page number usually go; force to column 2" (_-dfun-hook "lb-ht-toc-table-force-two-td") ;; (let (lb-bound lb-cnt lb-rc) ;;; ;;; ;;; Chapter I ^M ;;; ;;; (goto-char (point-max)) (search-backward-string "
" nil t) (setq lb-cnt 0) (setq lb-bound (save-excursion (search-backward " " "\n")) ) lb-rc)) (defun lb-ht-toc-table-multi-part-base nil "Multi-part documents have a '-' in name=/href= value. Insert another A to left of first name='ABC-123' with '-123' removed" ;; (let (lb-hitlist lb-msnp0 lb-msnp1 lb-msnp2 lb-rc) ;;; 17 lines matching "name=\"[^-\"]*[-]" in buffer index.html. ;;; 220: ;;; 236: 118 ;;; 244: 123 (progn (goto-char (point-min)) (while (and (search-forward-regexp (concat "\\(name=\"\\)" "\\([^\"]+\\)\"") nil t) (progn (setq lb-msnp0 (match-string-no-properties 0)) (setq lb-msnp1 (match-string-no-properties 1)) (setq lb-msnp2 (match-string-no-properties 2)) t)) (if (and (_-sgml-markup-p) (not (_-sgml-comment-p)) (string= "a" (_-sgml-what-element)) (not (member lb-msnp2 lb-hitlist))) (setq lb-hitlist (append lb-hitlist (list lb-msnp2)))))) (goto-char (point-min)) (while (and (search-forward-regexp (concat "\\(name=\"\\)" "\\([^-\"]+\\)[-][^\"]+\"") nil t) (progn (setq lb-msnp0 (match-string-no-properties 0)) (setq lb-msnp1 (match-string-no-properties 1)) (setq lb-msnp2 (match-string-no-properties 2)) t)) (when (and (_-sgml-markup-p) (not (_-sgml-comment-p)) (string= "a" (_-sgml-what-element)) ;; fix? ;; If "N" found during first while, ;; ABORT upon finding "N-I" (same root!). (not (member lb-msnp2 lb-hitlist))) (search-backward "<") (insert (concat "\n\n")) (search-forward "117 ;;; 228: 117 (setq lb-pt-while (goto-char (point-max))) (while (and (goto-char lb-pt-while) (when (search-backward-regexp (concat "" "]+" ">" "[^0-9]*" ;; fix? ;; when would page "number" not be a number? "\\([0-9]+\\)" "") nil t) (setq lb-pt-while (match-beginning 0)) (setq lb-page_no_href (match-string-no-properties 1)))) (search-forward-string "a") (when (and ;; Combine HREF and page number for unique key. ;; Page number can have 2 HREFs: pg. 68: en/1982/3HU357/. (setq lb-href (_-sgml-attr-grab "href")) (string= "toc_page_number" (setq lb-class (_-sgml-attr-grab "class")))) (setq lb-page_no_href (concat lb-page_no_href "..." lb-href)) (when (string= "measure" arg1mode) (if (member lb-page_no_href lb-page_no_href-seen-list) (setq lb-rc (append lb-rc (list lb-page_no_href))))) (when (string= "cut" arg1mode) (when (member lb-page_no_href arg2list) (when (member lb-page_no_href lb-page_no_href-seen-list) ;; Saw it on way up (matching anchor below this one). ;; Delete whole A element b/c name= moved to 2nd TD.. (progn (search-backward-string "<") (search-forward-regexp (concat "]+>" "[^<]*" "")) (replace-match " ")) (progn ;; Delete toc_page_number in this TD since page # is gone. (while (search-backward "class=\"toc_page_number\"" (save-excursion (search-backward "" and ">>" at bottom: ;; file:///home/login/leninist.biz/en/1973/WICIR313/i0.html (_-dfun-hook "lb-ht-toc-table") ;; (let (lb-href lb-section lb-lag-2nd-level-numeric lb-td-data lb-rc) (insert "\n") (loop for n from 1 to (1- (length lbg-sections)) do (setq lb-section (nth (1- n) lbg-sections)) (loop for item in lb-section do (setq lb-td-data nil) (setq lb-href (cdr (nth n lbg-html-hrefs))) ;; If not 1st/2nd/3rd level NUMERIC, insert linked page number. (when (not (and (string= "NUMERIC" (cdr (assoc "TYPE" item))) (or (string= "1" (cdr (assoc "LVL" item))) ;; Chapters under Parts: /en/1980/CCCWP252/ (string= "2" (cdr (assoc "LVL" item))) ;; 2006.11.24 (string= "3" (cdr (assoc "LVL" item))) ))) ;; lbg-html-hrefs and lbg-sections should have same length. (if (not (nth n lbg-html-hrefs)) (error "%s: %s" "Missing HREFs after" (prin1-to-string (nth (1- n) lbg-html-hrefs)))) (setq lb-td-data (concat lb-td-data " \n")) ;; SEE: lb-ht-toc-table-page-nums-dupes ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv (setq lb-td-data (concat lb-td-data " ")) (setq lb-td-data (concat lb-td-data ;; td.toc_page_number "" (cdr (assoc "PG" item)) ;; td.toc_page_number "" )) (setq lb-td-data (concat lb-td-data "" " \n")) ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ) ;; fix? ;; ASSUMES there is a 2nd lvl ALPHA after ea. 2nd lvl NUMERIC. (if (and (string= "NUMERIC" (cdr (assoc "TYPE" item))) (or (string= "2" (cdr (assoc "LVL" item))) ;; 2006.11.24 (string= "3" (cdr (assoc "LVL" item))))) (setq lb-lag-2nd-level-numeric (cdr (assoc "STR" item))) (setq lb-td-data (concat lb-td-data " " "\n")) (setq lb-td-data (concat lb-td-data " \n\n")) (progn (if lb-lag-2nd-level-numeric (setq lb-td-data (concat lb-td-data lb-lag-2nd-level-numeric ;; 2007.08.27 "
" "\n" "\n"))) (setq lb-lag-2nd-level-numeric nil)) (setq lb-td-data (concat lb-td-data (cdr (assoc "STR" item)) "\n" "\n")) (setq lb-td-data (concat lb-td-data " " "\n")) ) (if lb-td-data (insert "
\n" (_-strip-br--M-9--^^-anchors ;; 2007.05.28 lb-td-data) " \n\n"))) ;; loop ) ;; loop (insert "
\n\n") lb-rc)) (defun lb-ht-toc-get-sect-str (arg1list arg2lvl arg3type) "Return heading string from list ARG1 with level ARG2 of type ARG3" ;; (lb-ht-toc-get-sect-str (nth 1 lbg-sections) "1" "NUMERIC") ;; (lb-ht-toc-get-sect-str (nth 1 lbg-sections) "1" "ALPHA") ;; (lb-ht-toc-get-sect-str (nth 1 lbg-sections) "2" "ALPHA") (if nil (_-dfun-hook (concat "lb-ht-toc-get-sect-str" " " (prin1-to-string arg1list) "/" arg2lvl "/" arg3type)) ) (_-dfun-hook "lb-ht-toc-get-sect-str") ;; (let (lb-pf lb-item lb-rc) (loop for lb-item in arg1list do (if (and (string= arg2lvl (cdr (assoc "LVL" lb-item))) (string= arg3type (cdr (assoc "TYPE" lb-item)))) (if lb-rc (error "%s: %s" "Already have one (got two LVL1s?)" lb-rc) (setq lb-rc (cdr (assoc "STR" lb-item)))))) (if (and ;; Do not throw error if not found. nil (not lb-rc)) (error "%s: %s" (concat "Did not find " arg2lvl "/" arg3type) (prin1-to-string arg1list))) lb-rc)) ;; (lb-ht-toc-get-section) ;; ;; (setq lbg-text-indextx "/home/login/leninist.biz/en/1973/WICIR313/index.tx") ;; (lb-ht-toc-get-section 1) ;; (lb-ht-toc-get-section 15) ;; ;; MAX: ;; Last section is not real, it just marks end of last real section. ;; (lb-ht-toc-get-section (1- (length lbg-sections))) (defun lb-ht-toc-get-section (&optional arg1n-get-sect arg2nopop) ;)(05 a. "Called by two functions: lb-ht-generate-wholesome-text lb-ht-footnote-pop-from-next-section Optional ARG1 is section number (needed when popping footnote from next section); defaults to lbg-i-from1 set within a loop. In simplest case, return global variable lbg-next-section if non-nil and set it to nil (ARG1 is completely ignored). Value of lbg-next-section is set to next section only by function lb-ht-footnote-pop-from-next-section when the footnote text from next section, needed to finish current section, needs to be inserted at bottom of current section. Value of lbg-next-section is always set to nil by this function after non-nil value is assigned to return code (thus, ARG1 is ignored). Otherwise, if lbg-next-section is nil, return section bounded by 'PT' points of sections ARG1 and (1+ ARG1) in lbg-sections. Add page number at top *OR* bottom, depending on location of page numbers. Add '\\n\\n[0]\\n\\n' at top *OR* bottom, depending on location of page numbers. Insert '\\n\\n~\\n\\n' at top *AND* bottom to force double-newlines around page numbers. ARG1 is a section number (one-based, where 1 retrieves (nth (1- 1)).)" (_-dfun-hook "lb-ht-toc-get-section") ;; (let (lb-pf lb-beg lb-end lb-cnt lb-buffer lb-^^N^^ lb-pt lb-page-number-maybe-insert-at-top lb-page-number-maybe-insert-at-bottom (lb-buffer-was-current (current-buffer)) _str _lvl _beg _end ;; (lb-fly t) ;; debug - 2007.07.31 lb-fly ;; keep debuf off - 2007.11.02 lb-rc) (if (null arg1n-get-sect) (setq arg1n-get-sect lbg-i-from1)) (if (> arg1n-get-sect (1- (length lbg-sections))) (error "%s: %s" (concat "N too high (" (int-to-string arg1n-get-sect) ")") (_-buffer-substring-from- nil 200))) (with-temp-buffer (setq _-where-page-numbers _-where-page-numbers-global) ;; (setq lbg-next-section nil) (if lbg-next-section (progn (insert lbg-next-section) (setq lbg-next-section nil)) ;; ------------------------------------------------------- (_-ifcl lbg-text-indextx) ;; Get page number for optional insert before deleting (not ;; optional if page numbers at top. (progn (setq lb-beg (cdr (assoc "PT" (car (nth (1- arg1n-get-sect) lbg-sections))))) (setq lb-end (cdr (assoc "PT" (car (nth arg1n-get-sect lbg-sections)))))) (if (and (string= "top" _-where-page-numbers) (goto-char lb-beg)) (save-excursion (if (and (not (search-backward-regexp lb-re-bracketed-para-integer nil t)) ;; 2007.08.14 (not (search-backward-regexp lb-re-bracketed-para-integer-top-of-file nil t))) (error "%s: %s" lb-re-bracketed-para-integer (_-buffer-substring-from-))) (setq lb-page-number-maybe-insert-at-top (match-string-no-properties 0)))) (if (and (string= "bottom" _-where-page-numbers) (goto-char lb-end)) (save-excursion (if (not (search-forward-regexp lb-re-bracketed-para-integer nil t)) (error "%s: %s" lb-re-bracketed-para-integer (_-buffer-substring-from-))) (setq lb-page-number-maybe-insert-at-bottom (match-string-no-properties 0)))) ;; fix! ;; Must treat running headers the same as page numbers! In ;; addition, when a section breaks at a page break, a running ;; header at the end of a section (which is really the header for ;; the next section on the next page) should be ignored, as ;; indicated by lack of any cdata after running header at bottom. (progn ;; Delete regions outside section. (delete-region lb-end (point-max)) (delete-region (point-min) lb-beg) ;; Join word fragments by deleting hyphens. ;; First line should always have _LVL tag. (goto-char (point-min)) (if (not (_-blank-line-p)) (insert "\n")) ;; JUST 1. (goto-char (point-max)) (if (not (_-blank-line-p)) (insert "\n\n")) ;; NEED 2. ) ) ;; ON-THE-FLY. Either fresh text from index.txt or lbg-next-section. ;; 2007.02.17 (progn ;; Change LVLs after lbg-max-levels-for-chunking to H9 (if lb-fly (write-region (point-min) (point-max) "~/fly")) (goto-char (point-min)) (while (and (search-forward-regexp lb-re-__-lvl nil t) (setq _beg (match-beginning 0)) (setq _end (match-end 0)) (setq _str (match-string-no-properties 1)) (setq _lvl (match-string-no-properties 2))) (when (> (_-string-to-int _lvl) (_-string-to-int lbg-max-levels-for-chunking)) (delete-region _beg _end) (_-move-forward-whitespace) (insert (concat "" "\n")) (goto-char (cdr (_-where-double-newlines))) (_-move-backward-whitespace t) (insert (concat "")) ))) (progn ;; Clean-up endings. (if lb-fly (write-region (point-min) (point-max) "~/fly")) ;; fix! top! In addition to page numbers, insert running ;; headers, too. ;; fix! bottom! Delete empty page fragments when a top page ;; number and/or running header are included at bottom of current ;; section because next section begins at top of first page after ;; end of this section. Do __RUNNING_HEADER_RIGHT__, ;; __RUNNING_HEADER_LEFT__ and __NOTE__ (with set-register). (progn ;; Delete running header for next section? (goto-char (point-max)) (if (setq lb-pt (lb-tx-para-move-back-and-skipover-re- (concat "__\\(RUNNING_HEADER_" ;; fix? ;; Would this delete "footnote cont." notes? ;; "\\|NOTES?__" "\\)" ) )) (delete-region lb-pt (point-max))) ;; Point will now be at beginning of paragraph ;; that does not start with the above regexp, even ;; though return value, if non-nil, is lowest buffer ;; point where above regexp was found. ;; On line with page number from top of next page from next section? (if (and (string= "top" _-where-page-numbers) ;; fix! replace with tx-page-number-p ! (string-match lb-re-bracketed-integer-anchored (car (_-para t t)))) (_-para-delete)) ) ) (progn ;; Add missing information to top and bottom. ;; If page numbers at top, insert page number at top. (when (string= "top" _-where-page-numbers) (if lb-fly (write-region (point-min) (point-max) "~/fly")) (progn (goto-char (point-min)) (_-move-forward-whitespace)) (if (not (string-match lb-re-bracketed-integer-anchored (car (_-para t t)))) (insert lb-page-number-maybe-insert-at-top))) ;; If page numbers at bottom, insert page number at bottom. (when (string= "bottom" _-where-page-numbers) (if lb-fly (write-region (point-min) (point-max) "~/fly")) ;; fix? ;; Insert blank line if running header not inserted? (progn (goto-char (point-max)) (_-move-backward-whitespace)) (if (not (string-match lb-re-bracketed-integer-anchored (car (_-para t t)))) (insert lb-page-number-maybe-insert-at-bottom))) ;; fix! ;; Do not insert random "~" at top/bottom because it could ;; mask a page number at top/bottom unless ;; _-move-backward-whitespace includes "~" as part of whitespace ;; expression followed by _-move-forward-whitespace w/o "~" as ;; part of whitespace regexp. Or, make those functions recursive ;; if backward stops to right of "~" or forward stops to left of ;; "~". (progn (if lb-fly (write-region (point-min) (point-max) "~/fly")) (goto-char (point-min)) (if (not (_-blank-line-p)) (error "%s: %s" "Expecting blank line" "at top.")) ;; TEST: Empty page at top when page numbers at bottom of page? (lb-tx-page-point-away-from-page-number) (goto-char (point-max)) (if (not (_-blank-line-p)) (error "%s: %s" "Expecting blank line" "at bottom.")) ;; TEST: Empty page at bottom when page numbers at top of page? (lb-tx-page-point-away-from-page-number)) ) ;; Set original page numbers. (if (not arg2nopop) (progn (goto-char (point-max)) (search-backward-regexp "[a-z]") (goto-char (car (_-where-double-newlines))) (setq lbg-original-page-last (lb-tx-what-page)) (goto-char (point-min)) (goto-char (cdr (_-where-double-newlines))) (search-forward-regexp "[a-z]") (setq lbg-original-page-first (lb-tx-what-page)))) ;; Delete ... (if lb-fly (write-region (point-min) (point-max) "~/fly")) (lb-tx-zap-paragraphs (concat "__CHILD_CITATION_" "\\(BEG\\|END\\)" "__")) ;; Delete comments. (if lb-fly (write-region (point-min) (point-max) "~/fly")) (lb-tx-zap-paragraphs lb-re-__-comment) (when nil ;; Force two lines before first page number // after last page number. (progn (goto-char (point-min)) (insert "\n\n~\n\n" (if (not (string= "top" _-where-page-numbers)) "[0]" "") "\n\n") (goto-char (point-max)) (insert "\n\n" (if (string= "top" _-where-page-numbers) "[0]" "") "\n\n~\n\n"))) ;; MOVED HERE FROM lb-ht-generate-wholesome-text. ;; ;; Delete headings from body. ;; fix? Keep __ALPHA_LVL3__ headings! ;; OK: lb-re-__-lvl4chunking-real has just 1 and 2. ;; ;; 2006.11.28 - Took __NUMERIC_LVL[123]_CDATA out of book.htmm. ;; 2006.11.28 - Took __ALPHA_LVL[123]_CDATA out of book.htmm. ;; 2006.11.28 - That will prevent errors when checking footnote anchors. ;; (lb-tx-zap-paragraphs lb-re-__-lvl4chunking-real) ;; vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv ;; NOTE: Do first: lb-ht-footnotes-balancer-next-page-next-section ;; EXAMPLE: Page 148: ~/leninist.biz/en/1976/GPSPW3PP/20060825/199.tx ;; BECAUSE: Inserts are pushed down from _-_-_ ;; ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ;; MOVED HERE FROM lb-ht-generate-wholesome-text. ;; ;; -------------------------------------------- OK, now what? ;; Footnotes might get split between sections! Two different types ;; of split. Both types of split need to fetch footnote data from ;; first page of next section. ;; -------------------------------------------- ;; Do all footnotes on last page of this section have matching anchors? ;; Go to last page of this section. Search backwards through body ;; for "^^*^^". ;; If no matching "^^*^^" in footnotes area, get "***", "**", "**" ;; from next section, adding fetched footnote data under _-_-_ (push ;; down, i.e., "**" is inserted above "***"). ;; buffer->~/foo ;; (if (= 10 lbg-i-from1) (error "%s" (_-buffer-substring-from-))) (if lb-fly (write-region (point-min) (point-max) "~/fly")) (if (not arg2nopop) (lb-ht-footnotes-balancer-anchor-mismatch)) ;)(05 c ;; MOVED HERE FROM lb-ht-generate-wholesome-text. ;; ;; First footnote datum (full or partial footnote) in next section ;; may be continuation of footnote that started on next-to-last page ;; of this section (a partial footnote). (if lb-fly (write-region (point-min) (point-max) "~/fly")) (if (not arg2nopop) (lb-ht-footnotes-balancer-next-page-next-section)) ;)(05 b ;; MOVED HERE FROM lb-ht-generate-wholesome-text. ;; ;; Shrink. (_-compress-multiple-newlines) ;; (setq lb-rc (buffer-string))) ;; lia-tx.el: (set (make-local-variable '_-where-page-numbers) (setq _-where-page-numbers _-where-page-numbers-global) ;; 2006.11.29 (setq lbg-this-section lb-rc) lb-rc)) ;; (lb-ht-toc-get-max-lvl (nth 1 lbg-sections)) (defun lb-ht-toc-get-max-lvl (arg1section_list) "Return largest integer from all (\"LVL\" . \"999\") in section ARG1" ;; TOO MANY: (_-dfun-hook "lb-ht-toc-get-max-lvl") ;; (let (lb-pf lb-item lb-n (lb-max -1)) (loop for lb-item in arg1section_list do (if (> (setq lb-n (string-to-int (cdr (assoc "LVL" lb-item)))) lb-max) (setq lb-max lb-n))) lb-max)) ;; (lb-ht-toc-parse-tx-sections lbg-text-indextxlog) (defun lb-ht-toc-parse-tx-sections (arg1pflog) "Inserts file ARG1 into temp-buffer and applies lb-ht-harvest-levels, among other things. Returns list of sections" (_-dfun-hook "lb-ht-toc-parse-tx-sections") ;; (let (lb-pf lb-pt lb-pg lb-list lb-str lb-msnp0 lb-cnt lb-max lb-re ;; Globals: __TITLE__ __SUBTITLE__ __SUBTITLE2__ lb-rc-sections) ;; Harvest sections. (with-temp-buffer (_-ifcl arg1pflog) (progn ;; Store titles. (goto-char (point-min)) (setq __TITLE__ (setq __SUBTITLE__ (setq __SUBTITLE2__ nil))) ;; (while (search-forward-regexp lb-re-__-titles nil t) (search-forward-regexp lb-re-__-titles nil t) ;;skip over 2nd one (setq lb-msnp0 (match-string-no-properties 0)) (setq lb-str (_-normalize-whitespace (buffer-substring (point) (cdr (_-where-double-newlines))))) (cond ((string= "__TITLE__" lb-msnp0) (setq __TITLE__ lb-str)) ((string= "__SUBTITLE__" lb-msnp0) (setq __SUBTITLE__ lb-str)) ((string= "__SUBTITLE2__" lb-msnp0) (setq __SUBTITLE2__ lb-str))))) (progn ;; Find "real" sections (where "9" is not "0" in: "LVL9"). (goto-char (point-min)) (setq lb-rc-sections nil) (while (and (search-forward-regexp lb-re-__-lvl4chunking-real nil t) (goto-char (match-beginning 0))) (_-app 'lb-rc-sections (list ;; This function will harvest ;; multiple consecutive levels in a row. (lb-ht-harvest-levels))))) ;;xxxtender 6 ;; Find where last section ends by searching for "LVL0" section. ;; NOTE: This search is mandatory, unlike one above. ;; fix! fix? ;; Use [END] instead of __ALPHA_LVL0__ ;; But, this will affect chunking of sections! ;; Maybe OK to have "[BEGIN]" without matching "[END]". (if (and (search-forward-regexp (setq lb-re (progn (string-match "[[][0-9][-][0-9][]]" lb-re-__-lvl4chunking-real) (replace-match "0" t t lb-re-__-lvl4chunking-real 0))) nil t) (goto-char (match-beginning 0))) ;; fix? ;; use (_-app ??? (setq lb-rc-sections (append lb-rc-sections (list (lb-ht-harvest-levels)))) ;; Here is the difference: (error "%s: %s" (concat "Did not find " lb-re) ;; fix! (concat "\n" (_-buffer-substring-from-)) ))) (progn (setq lbg-sections-max-levels-list (list)) (setq lbg-sections-max-levels "0") (setq lb-cnt 0) (loop for list-outer in lb-rc-sections do (setq lb-cnt (1+ lb-cnt)) ;; lbg-i-from1 (setq lb-max "0") (loop for list-inner in list-outer do (setq lb-str (cdr (assoc "LVL" list-inner))) (if (> (string-to-int lb-str) (string-to-int lbg-sections-max-levels)) (setq lbg-sections-max-levels lb-str)) (if (> (string-to-int lb-str) (string-to-int lb-max)) (setq lb-max lb-str))) (setq lbg-sections-max-levels-list (append lbg-sections-max-levels-list (list (list lb-cnt lb-max)))))) lb-rc-sections)) ;; (lb-ht-toc-get-heading-up 12 "2" "ALPHA") (defun lb-ht-toc-get-heading-up (arg1i1 arg2lvl arg3type) "Look for heading type ARG3 having level ARG2 starting at ARG1 (one-based). ARG2 is ARG1 passed to lb-ht-toc-get-headings and runs from 1 to 1 minus length of lbg-sections" ;; (_-dfun-hook (concat "lb-ht-toc-get-heading-up" " " arg1i1 " / " arg2lvl " / " arg3type)) (let (lb-section lb-alpha lb-numeric lb-rc) ;; 2006.11.23 - new method. (loop for i from (1- arg1i1) downto 1 do (progn ;; outer. (progn (setq lb-section (nth (1- i) lbg-sections)) (setq lb-numeric (lb-ht-toc-get-sect-str lb-section arg2lvl "NUMERIC")) (setq lb-alpha (lb-ht-toc-get-sect-str lb-section arg2lvl "ALPHA")) ;; What we got? (list lb-numeric lb-alpha)) ;; If one found at appropriate level, return right one and stop. (cond ((and (string= "NUMERIC" arg3type) lb-numeric) (setq lb-rc lb-numeric)) ((and (string= "ALPHA" arg3type) lb-alpha) (setq lb-rc lb-alpha))) (if lb-rc (setq i -1)) lb-rc) ;; outer ) ;; loop lb-rc)) ;; (lb-ht-toc-get-headings 1) => (nil "INTRODUCTION" nil) ;; ;; (lb-ht-toc-get-headings 1) => (nil "INTRODUCTION" nil) ;; (lb-ht-toc-get-headings 2) ;; => ("CHAPTER ONE" "BETWEEN SCIENCE ;; AND METAPHYSICS" "1. METAPHYSICS AND ;; ANTI-METAPHYSICS OF POSITIVISM") ;; (lb-ht-toc-get-headings 3) ;; => ("CHAPTER ONE" "BETWEEN SCIENCE ;; AND METAPHYSICS" "2. METAPHYSICS ;; OF ``CRITICAL RATIONALISM''") ;; (lb-ht-toc-get-headings 5) ;; (lb-ht-toc-get-headings 16) => (nil "SUBJECT INDEX" nil) ;; (lb-ht-toc-get-headings 17) => nil ;; (defun lb-ht-toc-get-headings (arg1i1 &optional arg2fillerup arg3noerror) "Return (list lb-numeric1 lb-alpha1 ...2 ...2 ...3 ...3) using function lb-ht-toc-get-sect-str. ARG1 is section number (one-based). ARG1 from 1 to (1- (length lbg-sections)) since last section is a dummy. Optional ARG2 will try to fill empty slots using data from previous sections. If largest LVL of section is > 1, uses function lb-ht-toc-get-heading-up to get LVL1 data (and maybe LVL2) if it has to come from previous section headers. Optional ARG3, if non-nil, will prevent error if ARG1 is out-of-range. " (_-dfun-hook "lb-ht-toc-get-headings") ;; (let (lb-pf lb-section lb-lvl-max lb-cons lb-numeric1 lb-alpha1 lb-numeric2 lb-alpha2 lb-numeric3 lb-alpha3 _rc) (if (not arg3noerror) (if (< arg1i1 1) (error "%s: %s" "too small" (prin1-to-string arg1i1)) (if (> arg1i1 ;; 2006.11.30 - Must be entry for __ALPHA_LVL0__ in index.tab ;; (1- (length lbg-sections)) (length lbg-sections) ) (error "%s: %s" "too big" (prin1-to-string arg1i1))))) ;; MAIN: (when (and (>= arg1i1 1) (<= arg1i1 (1- (length lbg-sections)))) ;; Try to extract three pairs from this section. ;; It will be rare for a section to have all 3. (progn (setq lb-section (nth (1- arg1i1) lbg-sections)) (setq lb-lvl-max (lb-ht-toc-get-max-lvl lb-section)) (setq lb-numeric1 (lb-ht-toc-get-sect-str lb-section ;;xxxtender 10 "1" "NUMERIC")) (setq lb-alpha1 (lb-ht-toc-get-sect-str lb-section "1" "ALPHA")) (setq lb-numeric2 (lb-ht-toc-get-sect-str lb-section "2" "NUMERIC")) (setq lb-alpha2 (lb-ht-toc-get-sect-str lb-section "2" "ALPHA")) ;; 2006.11.23 (setq lb-numeric3 (lb-ht-toc-get-sect-str lb-section "3" "NUMERIC")) (setq lb-alpha3 (lb-ht-toc-get-sect-str lb-section "3" "ALPHA")) ;; FEEDBACK - What we got? (list lb-numeric1 lb-alpha1 lb-numeric2 lb-alpha2 lb-numeric3 lb-alpha3)) ;; Fill empty slots using previous heading groups. (when arg2fillerup ;; fix? ;; How to make sure the numeric comes from the current heading group? ;; 2006.11.23 - Changed to allow for MAXIMUM of 3 (was 2). ;; MAXIMUM is 2 or 3. (when (> lb-lvl-max 1) (if (not lb-numeric1) ;; numeric (setq lb-numeric1 ;; numeric (lb-ht-toc-get-heading-up arg1i1 "1" "NUMERIC"))) ;; numeric ;; (if (not lb-alpha1) ;; alpha (setq lb-alpha1 ;; alpha (lb-ht-toc-get-heading-up arg1i1 "1" "ALPHA")))) ;; alpha ;; MAXIMUM is 3. (when (> lb-lvl-max 2) (if (not lb-numeric2) ;; numeric (setq lb-numeric2 ;; numeric (lb-ht-toc-get-heading-up arg1i1 "2" "NUMERIC"))) ;; numeric ;; (if (not lb-alpha2) ;; alpha (setq lb-alpha2 ;; alpha (lb-ht-toc-get-heading-up arg1i1 "2" "ALPHA")))) ;; alpha ;; What we got? (list lb-numeric1 lb-alpha1 lb-numeric2 lb-alpha2 lb-numeric3 lb-alpha3)) ;; fillerup? ) ;; progn ;; (if (and (null lb-numeric1) (null lb-alpha1) (null lb-numeric2) (null lb-alpha2) (null lb-numeric3) (null lb-alpha3)) nil (setq _rc (list lb-numeric1 lb-alpha1 lb-numeric2 lb-alpha2 lb-numeric3 lb-alpha3))) _rc)) ;; (defun lb-ht-toc-parse-a-__heading__-para nil "Return list of conses from heading paragraph in log file. TYPE, LVL, PG, PT, and STR" ;; ;; __NUMERIC_LVL1__ 28133 ;; __NUMERIC_LVL1__ ;; CHAPTER ONE (let (lb-pf lb-re lb-flag lb-type lb-lvl lb-msnp0 lb-heading lb-end _rc) (when (and (looking-at ;; fix? lb-re-__-lvl4chunking-real ? lb-re-__-lvl4chunking ) (progn ;; arg1 was once '(match-data)' ... (set-match-data arg1md) (setq lb-type (match-string 1)) (setq lb-lvl (match-string 2)) (setq lb-msnp0 (match-string-no-properties 0)) (setq lb-end (match-end 0)) (setq lb-flag t))) ;; (replace-match "") (progn (goto-char lb-end) (search-forward-regexp "[0-9]+") ;; __NUMERIC_LVL1__ 28133 (setq lb-pt (string-to-int (match-string 0)))) ;; (replace-match "") (progn (_-move-forward-whitespace) (if (not (looking-at lb-msnp0)) (error "%s: %s" "Expecting a 2nd one" (concat lb-msnp0 "\n\n" (_-buffer-substring-from-))) (setq lb-end (match-end 0)))) ;; (replace-match "")) (progn (goto-char lb-end) (_-move-forward-whitespace) (setq lb-heading (buffer-substring (point) (cdr (_-where-double-newlines))))) (setq _rc (list (cons "TYPE" lb-type) (cons "LVL" lb-lvl) (cons "PG" ;; 2006.11.27 ;; (lb-anyformat-what-page) ;; NOTE: If pg. numbers at bottom, must have page "0". (save-excursion ;;PG# 22592 7 ;;6 (if (not (search-backward-regexp (setq lb-re (concat "^" "PG# [0-9]+ " ;; 2007.03.01 ;; "\\([0-9]+\\)" "\\([-]?[0-9]+\\)" "$")) nil t)) (error "%s: %s" lb-re (_-buffer-substring-from-)) (match-string 1)))) (cons "PT" lb-pt) (cons "STR" lb-heading)))) ;; fix? ;; Disallow this function from positioning for next one? (progn (goto-char (cdr (_-where-double-newlines))) (_-move-forward-whitespace)) ;; Position for next one. _rc)) ;; (lb-ht-generate-toc) (defun lb-ht-generate-toc nil ;)(02 c "" (_-dfun-hook "lb-ht-generate-toc") ;; (let (lb-str lb-rc) (progn (_-set-buffer-to-pf lbg-html-index) (toggle-read-only nil) (lb-ht-common-__)) ;; Delete navigation table at bottom and preceding HR. (progn (goto-char (point-max)) (search-backward ""))) ;; Add TOC. (progn (goto-char (point-min)) (search-forward-string "%%data%%") (_-para-delete) ;; MAIN: (lb-ht-toc-table)) ;)(06 a (progn ;; 2006.08.22 (lb-ht-toc-table-page-nums-dupes "cut" (lb-ht-toc-table-page-nums-dupes "measure")) ;; 2006.09.07 ;; NOTE: There will be duplicate name= attributes in A elements. ;; 2006.08.22 ;; (error "%s" (_-buffer-substring-from-)) (lb-ht-toc-table-force-two-td) ;; 2006.08.29 - add another A with basename for multi-part docs. (lb-ht-toc-table-multi-part-base) ;; ) (progn (lb-ht-sub-__ lb-ht-__) ;)(0 (lb-tx-zap-paragraphs lb-re-__)) ;)(0 ;; CSS: table[class="toc"] td[class=""] { (progn (goto-char (point-min)) (while (search-forward-string "
" nil t) (replace-match ""))) ;; 2006.12.11 ;; The index page looks too skinny and left-justified. I would make the ;; index page as wide as the text pages and/or add some more white-space ;; between the navigation bar on the left and the text of the index ;; page...so they look consistent. ;; ;; David (when ;; BUT. Does not look good centered in Opera. 2007.01.24. nil (goto-char (point-min)) (if (and (search-forward-string (setq lb-str "div id=\"main\"")) (_-sgml-comment-p)) (error "%s: %s" "Not expecting" "SGML comment") (search-forward-string "")) (if (and (search-forward-string (setq lb-str "div id=\"main\"")) (not (_-sgml-comment-p))) (error "%s: %s" "Not not expecting" "SGML comment") (search-backward-string "") (insert ""))) ;; (lb-mu-spawn-finale nil nil (list ;; Need this in both places. ;; Remove leading "#" signs from hrefs for index.html 'lb-ht-gen-del-leading-href-poundsign ;)(03 c. ;; 'lb-ht-gen-wrap-arrows-without-hrefs-span-disappear ;; 2007.08.07 '_-highascii2html_entities 'lb-ht-gen-del-%%notes%% 'lb-mu-hey-rocky)) ;; 2006.12.12 - Put TOC link back. (with-temp-buffer ;; 2007.08.07 - OFF - ;; (lb-ht-gen-del-self-href) ;; 2007.08.07 - OFF - ;; (lb-mu-href-delete-pound-dead-ends)) (when nil (_-ifcl lbg-html-index) (goto-char (point-min)) (if (not (search-forward-regexp (concat "TOC") nil t)) (error "%s: %s" "huh" "humpf") (replace-match "TOC")) (write-file lbg-html-index))) ;; (lb-lftp-dosomething-file lbg-html-index) ;; lb-rc)) ;; (setq lbg-html-hrefs (lb-toc-get-html-hrefs lbg-path-from-lang)) ;; (lb-toc-get-html-hrefs "en/1984/AP470") ;; (lb-toc-get-html-hrefs "en/1981/PCM336/") ;; (lb-toc-get-html-hrefs "en/1981/2HU327/") ;; (lb-toc-get-html-hrefs "en/1982/3HU357/") ;; (lb-toc-get-html-hrefs "en/1977/GPSPW1PP/") (defun lb-toc-get-html-hrefs (arg1subpath) "Get href= values from index.tab" ;; index.tab: -------------------------------------------- ;; # Emacs-Time-stamp: "2005-10-02 15:52:37" ;; # Emacs-File-stamp: "/home/login/leninist.biz/en/1984/AP470/index.tab" ;; hrefs 00 nil naletov00 contents ;; hrefs 01 i naletovw intro ("w" per R. Dumain) ;; hrefs 02 11 naletov11 c1s1 ;; fix! Disallow dupes/duplicates. (_-dfun-hook "lb-toc-get-html-hrefs") ;; (let (lb-pf lb-re lb-list lb-list-row lb-integer lb-list-integers-seen lb-integer-cnt lb-href lb-list-hrefs-seen lb-rc) (if (not (string-match "/$" arg1subpath)) (setq arg1subpath (concat arg1subpath "/"))) ;; Checks. (with-temp-buffer (_-ifcl (setq lb-pf (if (not arg1subpath) lbg-text-indextab (concat lb-home (lb-get-id-from-path arg1subpath) "/" lb-file-indextab)))) ;; (goto-char (point-min)) (if (= (point-max) 1) (error "%s: %s" "Empty file" lb-pf)) (if (not (search-forward "__ALPHA_LVL0__" nil t)) (error "%s: %s" "Missing" (concat "__ALPHA_LVL0__ >-< " lb-pf))) ) (loop for row in (_-something-to-list lb-pf t) do (setq lb-list-row ;; Only use data with NO embedded spaces! ;; huh? 2006.09.11 ;; 2006.12.04 ;; If SEPARATORS is absent, it defaults to "[ \f\t\n\r\v]+". ;; (split-string row) ;; => ("hrefs" "01" "Fo" "rward" "." "/") ;; (split-string row "[\f\t\n\r\v]+") ;; => ("hrefs" "01" "Fo rward " "." "/") (split-string row "[ ]*[\f\t\n\r\v][ ]*") ;; => ("hrefs" "01" "Fo rward" "." "/") ) (when (and ;; Standard comment. (not (string-match "^#" row)) ;; If value in column 1/2 ends with "#", treat as comment. (not (string-match "#$" (nth 0 lb-list-row))) (not (string-match "#$" (nth 1 lb-list-row)))) (cond ((or (string= "hrefs" (car lb-list-row)) ;; ESC c runs the command capitalize-word (string= "Hrefs" (car lb-list-row))) ;; -> (setq lb-integer (nth 1 lb-list-row)) ;; fix! clarification, please. documentation. what is this? ;; Allow "->" and "_>" ;; 2006.10.30 (if (string-match _-re-tab-use-_> (setq lb-href (nth 2 lb-list-row))) (setq lb-href (nth 3 lb-list-row))) ;; Integers in order? (if (not lb-integer-cnt) (setq lb-integer-cnt (string-to-int lb-integer)) (if (not (= (setq lb-integer-cnt (1+ lb-integer-cnt)) (string-to-int lb-integer))) (error "%s: %s" (concat "Integers not in order at " lb-integer) lb-pf))) ;; string= --------------------------------- ;; To get nil, insert "nil" in tab file. (if (string= "nil" lb-href) (setq lb-href nil)) ;; Disallow "." (often there by accident). (if (string= "." lb-href) (error "%s: %s" "Not allowed" (concat lb-href " >-< " lb-pf))) ;; string-match --------------------------------- ;; Disallow "\'o" ... etc. ... ;;; ;;;$ find . -follow -name index.tab | xargs -i cut -f3 '{}' > foo ;;; ;;;(while (search-forward-regexp "[^\n]" nil t) ;;; (replace-match (concat "\n" (match-string 0)))) ;;; ;;;$ sort foo | uniq -c > foo2 ;;; ;;; ;;; 3 ! ;;; 22 " ;;; 3 & ;;; 20 ' ;;; 25 ( ;;; 9 ) ;;; 7 * ;;; 3 + ;;; 1 , ;;; 2099 - ;;; 2879 . ;;; 1 / ;;; 107 0 ;;; 319 1 ;;; 227 2 ;;; 205 3 ;;; 122 4 ;;; 89 5 ;;; 73 6 ;;; 53 7 ;;; 78 8 ;;; 135 9 ;;; 4 : ;;; 41 > ;;; ;;; 480 A ;;; 394 B ;;; 682 [C-Z] ;;; ;;; 10 [ ;;; 10 ] ;;; 163 _ ;;; 1 ` ;;; ;;; 1704 a ;;; 155 b ;;; 890 [c-z] ;;; ;; 2006.12.19 (if (and (string-match (setq lb-re "[^-.,)(0-9A-Za-z]") lb-href) (not (string= "__ALPHA_LVL0__" lb-href))) (error "%s: %s" (concat "No " lb-re " characters allowed") (concat lb-href " >-< " lb-pf))) ;; Disallow "_" (using periods and hypens only). (if (and (string-match "_" lb-href) (not (string= "__ALPHA_LVL0__" lb-href))) (error "%s: %s" "No _ allowed" (concat lb-href " >-< " lb-pf))) ;; Disallow "--" (URL will be put into SGML comment). (if (string-match "--" lb-href) (error "%s: %s" "No -- allowed" (concat lb-href " >-< " lb-pf))) ;; Disallow "'" (screws up shell and lftp). (if (string-match "[']" lb-href) (error "%s: %s" "No ' allowed" (concat lb-href " >-< " lb-pf))) ;; Disallow "." at end. (if (string-match "[.]$" lb-href) (error "%s: %s" "No . allowed at end" (concat lb-href " >-< " lb-pf))) ;; fix! Exclude all other extentsions! ;; 2007.04.07 - ".book" is application/x-maker in Mozilla: ;; Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) ;; Gecko/20020623 Debian/1.0.0-0.woody.1 ;; 2006.12.08 - ".class" crashes Mozilla: ;; Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.0) ;; Gecko/20020623 Debian/1.0.0-0.woody.1 (if (string-match (setq lb-re (concat "[.]" "\\(" "CLASS" "\\|BOOK" "\\)" "$")) (upcase lb-href)) (error "%s: %s" "Trailing .WORD not allowed" (concat lb-href "\n in: " lb-pf "\n"))) ;; 2006.12.04 - "4-Literature.and.Art" (if (string-match (setq lb-re "[.][^.][^.][^.]$") lb-href) (error "%s: %s" "Maybe be interpreted as a file extention" (concat lb-href " >-< " lb-pf))) ;; 2006.12.06 - "...LIX" ;; 2006.12.23 - SCRAP. Test for 3-character extension suffices. (if (and (string-match (setq lb-re (concat "[.]" lb-re-roman-numerals "$")) lb-href) nil) ;; 2006.12.23 (error "%s: %s" "No dot-roman-numeral allowed" (concat lb-href " >-< " lb-pf))) ;; ------------------------------------------------------- (if (member lb-integer lb-list-integers-seen) (error "%s: %s" "Already seen" lb-integer) (setq lb-list-integers-seen (append lb-list-integers-seen (list lb-integer)))) (if (member lb-href lb-list-hrefs-seen) (error "%s: %s" "Already seen" lb-href) (setq lb-list-hrefs-seen (append lb-list-hrefs-seen (list lb-href)))) (setq lb-rc (append lb-rc (list (cons ;; Integer. (string-to-int lb-integer) ;; HREF. lb-href)))) ) ;; hrefs ) ;; cond )) ;; loop ;; fix! ;; This should be an expandable associative array that allows "(assoc" to ;; be used to retrieve values. lb-rc)) (provide 'lb-toc) ;;; ;