diff --git a/docs/Makefile.in b/docs/Makefile.in index 66d75fa5..65995e45 100755 --- a/docs/Makefile.in +++ b/docs/Makefile.in @@ -46,6 +46,7 @@ web: FORCE @test -d phpweb || mkdir phpweb $(JADE) $(CATALOG) -d $(PHPWEB_STYLESHEET) -V use-output-dir -t sgml $(XMLDCL) manual.xml $(PHP) scripts/generate_web.php + $(PHP) scripts/html_syntax.php php phpweb/ test: $(NSGMLS) -i lang-$(LANG) -s $(XMLDCL) manual.xml diff --git a/docs/dsssl/common.dsl b/docs/dsssl/common.dsl index ad47f956..d8ce3c20 100644 --- a/docs/dsssl/common.dsl +++ b/docs/dsssl/common.dsl @@ -9,6 +9,7 @@ ;; Stylesheets Localization (define %default-language% "en") +(define %root-filename% "index") (define %use-id-as-filename% #t) (define %gentext-nav-tblwidth% "100%") (define %refentry-function% #t) @@ -23,24 +24,335 @@ (define %number-programlisting-lines% #f) (define %linenumber-mod% 1) (define %shade-verbatim% #t) - -(define ($generate-book-lot-list$) - ;; REFENTRY generate-book-lot-list - ;; PURP Which Lists of Titles should be produced for Books? - ;; DESC - ;; This parameter should be a list (possibly empty) of the elements - ;; for which Lists of Titles should be produced for each 'Book'. - ;; - ;; It is meaningless to put elements that do not have titles in this - ;; list. If elements with optional titles are placed in this list, only - ;; the instances of those elements that do have titles will appear in - ;; the LOT. - ;; - ;; /DESC - ;; AUTHOR N/A - ;; /REFENTRY - (list (normalize "table"))) +(define %prefers-ordinal-label-name-format% #f) +(define ($generate-book-lot-list$) (list)) (define (php-code code) (make processing-instruction data: (string-append "php " code "?"))) + +(define quicksort + (quicksort::generic null? car cdr append cons '())) + +(define nl-quicksort + (quicksort::generic node-list-empty? + node-list-first + node-list-rest + node-list + node-list + (empty-node-list))) + +(define quicksort::generic + (lambda(is-null? first others concat add empty) + (letrec ((collect + ;; Collect is an helper function doing the real work + + (lambda (pivot ls lgroup rgroup less?) + (if (is-null? ls) + (concat (impl lgroup less?) + (add pivot (impl rgroup less?))) + (if (less? pivot (first ls)) + (collect pivot (others ls) lgroup + (add (first ls) rgroup) + less?) + (collect pivot (others ls) + (add (first ls) lgroup) + rgroup + less?))))) + (impl + ;; impl first test some trivial sorting case and then call + ;; the procedure collect + (lambda (ls less?) + (if (or (is-null? ls) (is-null? (others ls))) + ls + (collect (first ls) (others ls) empty empty less?))))) + ;; we return the new defined procedure + impl))) + +;; Polish definitions + +(define (gentext-pl-nav-next next) + (make sequence (literal "Nast\U-0119;pny"))) + +(define (book-titlepage-recto-elements) + (list (normalize "title") + (normalize "subtitle") + (normalize "graphic") + (normalize "mediaobject") + (normalize "corpauthor") + (normalize "authorgroup") + (normalize "author") + (normalize "editor") + (normalize "pubdate") + (normalize "copyright") + (normalize "abstract") + (normalize "legalnotice"))) + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;;;; +;;;; render function prototypes, esp. with optional arguments +;;;; for new docbook4 methodsynopsis tag and friends +;;;; +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + +;; helper function generating closing optional brackets +(define (methodsynopsis-generate-closing-optionals nl) + (if (node-list-empty? nl) + (empty-sosofo) ;; empty list -> do nothing + (make sequence ;; process list node + (if (or (and (attribute-string (normalize "choice") (node-list-first nl)) + (string=? "opt" (attribute-string (normalize "choice") (node-list-first nl))) + ) + (has-default-value (node-list-first nl))) + (literal %arg-choice-opt-close-str%) ;; is optional parameter -> close a bracket + (empty-sosofo) + ) + (methodsynopsis-generate-closing-optionals (node-list-rest nl)) ;; process rest of list + ) + ) + ) + +(define (is-true-optional nl) + (and (equal? (gi (parent nl)) (normalize "parameter")) + (equal? 0 (string-length (strip (data (preced nl))))) + (equal? 0 (string-length (strip (data (follow nl))))) + ) + ) + + +(define (has-true-optional nl) + (is-true-optional + (node-list-first-element + (select-elements + (descendants nl) + (normalize "optional")) + ) + ) + ) + + +(define (count-true-optionals nl) + (let loop + ((result 0) + (nl (select-elements (descendants nl) (normalize "optional"))) + ) + (if(node-list-empty? nl) + result + (if(is-true-optional(node-list-first nl)) + (loop (+ result 1) (node-list-rest nl)) + (loop result (node-list-rest nl)) + ) + ) + ) + ) + +(define (has-default-value nl) + (not (node-list-empty? ( select-elements (descendants nl) (normalize "initializer")))) + ) + +;; render classsynopsis +(element classsynopsis + (make sequence + (literal "class ") + (process-children-trim) + (literal "}") + ) +) + +(element ooclass (make sequence (process-children))) + +(element (ooclass classname) + (make sequence + ($bold-seq$ + (process-children-trim) + ) + (literal " { ") + (linebreak) + ) + ) + + + +;; render methodsynopsis +(element methodsynopsis + (make sequence + (process-children) ;; render content + (methodsynopsis-generate-closing-optionals (children (current-node))) ;; close optional brackets + (literal ")") ;; close parameter list + (linebreak) + ) +) + +(element constructorsynopsis + (make sequence + (process-children) ;; render content + (methodsynopsis-generate-closing-optionals (children (current-node))) ;; close optional brackets + (literal ")") ;; close parameter list + (linebreak) + ) +) + +;; render return type +(element (methodsynopsis type) + (make sequence + (process-children-trim) + (literal " ") + ) +) + +;; render function name +(element (methodsynopsis methodname) + (make sequence + ($bold-seq$ + (process-children-trim) + ) + (literal " ( ") ;; start parameter list + ) + ) + +(element (constructorsynopsis methodname) + (make sequence + ($bold-seq$ + (process-children-trim) + ) + (literal " ( ") ;; start parameter list + ) + ) + +;; render parameters +(element (methodsynopsis methodparam) + (make sequence + ;; special case -> first parameter is optional + (if (equal? (gi (ipreced (current-node))) (normalize "methodparam")) + (empty-sosofo) ;; have prev. parameters -> is not first + (if (or (equal? (attribute-string (normalize "choice")) "opt") + (has-default-value (current-node)) + ) + (literal %arg-choice-opt-open-str%) ;; generate opening bracket + (empty-sosofo) + ) + ) + + (process-children-trim) + + ;; have more parameters following me? + (if (equal? (gi (ifollow (current-node))) (normalize "methodparam")) + (make sequence + ;; is next parameter optional? + (if (or (equal? (attribute-string (normalize "choice") (ifollow (current-node))) "opt") + (has-default-value (ifollow (current-node))) + ) + (make sequence + (literal " ") + (literal %arg-choice-opt-open-str%) + ) + (empty-sosofo) + ) + ;; parameter list separator + (literal ", ") + ) + (empty-sosofo) + ) + ) + ) + + +;; render parameters +(element (constructorsynopsis methodparam) + (make sequence + ;; special case -> first parameter is optional + (if (equal? (gi (ipreced (current-node))) (normalize "methodparam")) + (empty-sosofo) ;; have prev. parameters -> is not first + (if (or (equal? (attribute-string (normalize "choice")) "opt") + (has-default-value (current-node)) + ) + (literal %arg-choice-opt-open-str%) ;; generate opening bracket + (empty-sosofo) + ) + ) + + (process-children-trim) + + ;; have more parameters following me? + (if (equal? (gi (ifollow (current-node))) (normalize "methodparam")) + (make sequence + ;; is next parameter optional? + (if (or (equal? (attribute-string (normalize "choice") (ifollow (current-node))) "opt") + (has-default-value (ifollow (current-node))) + ) + (make sequence + (literal " ") + (literal %arg-choice-opt-open-str%) + ) + (empty-sosofo) + ) + ;; parameter list separator + (literal ", ") + ) + (empty-sosofo) + ) + ) + ) + +;; special "void" return type tag +(element (methodsynopsis void) + (literal "void ") +) + + +;; render parameter type +(element (methodparam type) + (make sequence + (process-children-trim) + (literal " ") + ) + ) + +;; render parameter name +(element (methodparam parameter) + (make sequence + (process-children-trim) + ) + ) + +;; render default value +(element (methodparam initializer) + (make sequence + (literal "=") + ($italic-seq$ (process-children-trim)) + ) + ) + + +;; render fieldsynopsis +(element fieldsynopsis + (make sequence + (process-children) + (linebreak) + ) +) + +(element (fieldsynopsis type) + (make sequence + (process-children-trim) + (literal " ") + ) +) +(element (fieldsynopsis varname) + (make sequence + (process-children-trim) + ) +) + + + + +;; render SGML tags +(element sgmltag + (make sequence + ($bold-seq$ (literal "<")) + ($bold-seq$ (process-children)) + ($bold-seq$ (literal ">")) + ) +) + diff --git a/docs/dsssl/html-common.dsl b/docs/dsssl/html-common.dsl index 7fd772c5..54eb371f 100644 --- a/docs/dsssl/html-common.dsl +++ b/docs/dsssl/html-common.dsl @@ -3,19 +3,25 @@ ;; $Id$ ;; -;; Returns the depth of the auto-generated TOC (table of contents) that -;; should be made at the nd-level +;; Returns the depth of the auto-generated TOC (table of +;; contents) that should be made at the nd-level (define (toc-depth nd) - (if (string=? (gi nd) (normalize "book")) - 3 ; the depth of the top-level TOC + (if (string=? (gi nd) "book") + 2 ; the depth of the top-level TOC 1 ; the depth of all other TOCs )) +;; re-defining element-id as we need to get the id of the parent +;; element not only for title but also for question in the faq +(define (element-id #!optional (nd (current-node))) + (let ((elem (if (equal? (gi nd) (normalize "title")) (parent nd) + (if (equal? (gi nd) (normalize "question")) (parent nd) + nd)))) + (if (attribute-string (normalize "id") elem) + (attribute-string (normalize "id") elem) + (generate-anchor elem)))) - - - - +;; Make function definitions bold (element (funcdef function) ($bold-seq$ (make sequence @@ -25,44 +31,9 @@ ) -(define (is-true-optional nl) - (and (equal? (gi (parent nl)) (normalize "parameter")) - (equal? 0 (string-length (strip (data (preced nl))))) - (equal? 0 (string-length (strip (data (follow nl))))) - ) - ) - - -(define (has-true-optional nl) - (is-true-optional - (node-list-first-element - (select-elements - (descendants nl) - (normalize "optional")) - ) - ) - ) - - -(define (count-true-optionals nl) - (let loop - ((result 0) - (nl (select-elements (descendants nl) (normalize "optional"))) - ) - (if(node-list-empty? nl) - result - (if(is-true-optional(node-list-first nl)) - (loop (+ result 1) (node-list-rest nl)) - (loop result (node-list-rest nl)) - ) - ) - ) - ) - - -;; there are two different kinds of optionals -;; optional parameters and optional parameter parts -;; an optional parameter is identified by an optional tag +;; There are two different kinds of optionals +;; optional parameters and optional parameter parts. +;; An optional parameter is identified by an optional tag ;; with a parameter tag as its parent ;; and only whitespace between them (element optional @@ -72,257 +43,14 @@ (process-children-trim) ;; no - do '[...]' output (make sequence - (literal %arg-choice-opt-open-str%) - (process-children-trim) - (literal %arg-choice-opt-close-str%) - ) + (literal %arg-choice-opt-open-str%) + (process-children-trim) + (literal %arg-choice-opt-close-str%) + ) ) - ) - -;; now this is going to be tricky -(element paramdef - (make sequence - ;; special treatment for first parameter in funcsynopsis - (if (equal? (child-number (current-node)) 1) - ;; is first ? - (make sequence - ;; start parameter list - (literal "(") - ;; is optional ? - ( if (has-true-optional (current-node)) - (literal %arg-choice-opt-open-str%) - (empty-sosofo) - ) - ) - ;; not first - (empty-sosofo) - ) - - ;; - (process-children-trim) - - ;; special treatment for last parameter - (if (equal? (gi (ifollow (current-node))) (normalize "paramdef")) - ;; more parameters will follow - (make sequence - ;; next is optional ? - ( if (has-true-optional (ifollow (current-node))) - ;; optional - (make sequence - (literal " ") - (literal %arg-choice-opt-open-str%) - ) - ;; not optional - (empty-sosofo) - ) - (literal ", " ) - ) - ;; last parameter - (make sequence - (literal - (let loop ((result "")(count (count-true-optionals (parent (current-node))))) - (if (<= count 0) - result - (loop (string-append result %arg-choice-opt-close-str%)(- count 1)) - ) - ) - ) - ( literal ")" ) - ) - ) - ) - ) - - -(element function - (let* ((function-name (data (current-node))) - (linkend - (string-append - "function." - (string-replace - (string-replace function-name "_" "-") - "::" "."))) - (target (element-with-id linkend)) - (parent-gi (gi (parent)))) - (cond - ;; function names should be plain in FUNCDEF - ((equal? parent-gi "funcdef") - (process-children)) - - ;; if a valid ID for the target function is not found, or if the - ;; FUNCTION tag is within the definition of the same function, - ;; make it bold, add (), but don't make a link - ((or (node-list-empty? target) - (equal? (case-fold-down - (data (node-list-first - (select-elements - (node-list-first - (children - (select-elements - (children - (ancestor-member (parent) (list "refentry"))) - "refnamediv"))) - "refname")))) - function-name)) - ($bold-seq$ - (make sequence - (process-children) - (literal "()")))) - - ;; else make a link to the function and add () - (else - (make element gi: "A" - attributes: (list - (list "HREF" (href-to target))) - ($bold-seq$ - (make sequence - (process-children) - (literal - ) - (literal "()")))))))) - -(element command - (let* ((command-name (data (current-node))) - (linkend - (string-append - "language.function." - (string-replace - (string-replace command-name "_" ".") - "::" "."))) - (target (element-with-id linkend)) - (parent-gi (gi (parent)))) - (cond - ;; function names should be plain in FUNCDEF - ((equal? parent-gi "funcdef") - (process-children)) - - ;; if a valid ID for the target function is not found, or if the - ;; FUNCTION tag is within the definition of the same function, - ;; make it bold, add (), but don't make a link - ((or (node-list-empty? target) - (equal? (case-fold-down - (data (node-list-first - (select-elements - (node-list-first - (children - (select-elements - (children - (ancestor-member (parent) (list "refentry"))) - "refnamediv"))) - "refname")))) - command-name)) - ($bold-seq$ - (make sequence - (literal "{") - (process-children) - (literal "}")))) - - ;; else make a link to the function and add () - (else - (make element gi: "A" - attributes: (list - (list "HREF" (href-to target))) - ($bold-seq$ - (make sequence - (literal "{") - (process-children) - (literal "}")))))))) - -(element classname - (let* ((class-name (data (current-node))) - (linkend - (string-append - "class." - (string-replace - (case-fold-down class-name) "_" "-"))) - (target (element-with-id linkend)) - (parent-gi (gi (parent)))) - (cond - ;; function names should be plain in SYNOPSIS - ((equal? parent-gi "synopsis") - (process-children)) - - ;; if a valid ID for the target class is not found, or if the - ;; CLASSNAME tag is within the definition of the same class, - ;; make it bold, but don't make a link - ((or (node-list-empty? target) - (equal? (case-fold-down - (data (node-list-first - (select-elements - (node-list-first - (children - (select-elements - (children - (ancestor-member (parent) (list "refentry"))) - "refnamediv"))) - "refname")))) - class-name)) - ($bold-seq$ - (process-children))) - - ;; else make a link to the function and add () - (else - (make element gi: "A" - attributes: (list - (list "HREF" (href-to target))) - ($bold-seq$ - (process-children))))))) - - -(element constant - (let* ((constant-name (data (current-node))) - (linkend - (string-append "constant." - (case-fold-down - (string-replace constant-name "_" "-")))) - (target (element-with-id linkend)) - (parent-gi (gi (parent)))) - (cond -; ;; constant names should be plain in FUNCDEF -; ((equal? parent-gi "funcdef") -; (process-children)) - - ;; if a valid ID for the target constant is not found, or if the - ;; CONSTANT tag is within the definition of the same constant, - ;; make it bold, add (), but don't make a link - ((or (node-list-empty? target) - (equal? (case-fold-down - (data (node-list-first - (select-elements - (node-list-first - (children - (select-elements - (children - (ancestor-member (parent) (list "refentry"))) - "refnamediv"))) - "refname")))) - constant-name)) - ($bold-mono-seq$ - (process-children))) - - ;; else make a link to the function and add () - (else - (make element gi: "A" - attributes: (list - (list "HREF" (href-to target))) - ($bold-mono-seq$ - (process-children))))))) - - -(element example - (make sequence - (make element gi: "TABLE" - attributes: (list - (list "WIDTH" "100%") - (list "BORDER" "0") - (list "CELLPADDING" "0") - (list "CELLSPACING" "0") - (list "CLASS" "EXAMPLE")) - (make element gi: "TR" - (make element gi: "TD" - ($formal-object$)))))) - + ) +;; Print out parameters in italic (element (paramdef parameter) (make sequence font-posture: 'italic @@ -330,10 +58,128 @@ ) ) +;; Now this is going to be tricky +(element paramdef + (make sequence + ;; special treatment for first parameter in funcsynopsis + (if (equal? (child-number (current-node)) 1) + ;; is first ? + (make sequence + ;; start parameter list + (literal " (") + ;; is optional ? + ( if (has-true-optional (current-node)) + (literal %arg-choice-opt-open-str%) + (empty-sosofo) + ) + ) + ;; not first + (empty-sosofo) + ) + + ;; + (process-children-trim) + + ;; special treatment for last parameter + (if (equal? (gi (ifollow (current-node))) (normalize "paramdef")) + ;; more parameters will follow + (make sequence + ;; next is optional ? + ( if (has-true-optional (ifollow (current-node))) + ;; optional + (make sequence + (literal " ") + (literal %arg-choice-opt-open-str%) + ) + ;; not optional + (empty-sosofo) + ) + (literal ", " ) + ) + ;; last parameter + (make sequence + (literal + (let loop ((result "")(count (count-true-optionals (parent (current-node))))) + (if (<= count 0) + result + (loop (string-append result %arg-choice-opt-close-str%)(- count 1)) + ) + ) + ) + ( literal ")" ) + ) + ) + ) + ) + +(element function + (let* ((function-name (data (current-node))) + (linkend + (string-append + "function." + (case-fold-down (string-replace + (string-replace function-name "_" "-") + "::" ".")))) + (target (element-with-id linkend)) + (parent-gi (gi (parent)))) + (cond + ;; function names should be plain in FUNCDEF + ((equal? parent-gi "funcdef") + (process-children)) + + ;; If a valid ID for the target function is not found, or if the + ;; FUNCTION tag is within the definition of the same function, + ;; make it bold, add (), but don't make a link + ((or (node-list-empty? target) + (equal? (case-fold-down + (data (node-list-first + (select-elements + (node-list-first + (children + (select-elements + (children + (ancestor-member (parent) (list "refentry"))) + "refnamediv"))) + "refname")))) + (case-fold-down function-name))) + ($bold-seq$ + (make sequence + (process-children) + (literal "()")))) + + ;; Else make a link to the function and add () + (else + (make element gi: "A" + attributes: (list + (list "HREF" (href-to target))) + ($bold-seq$ + (make sequence + (process-children) + (literal + ) + (literal "()")))))))) + + +;; Dispaly of examples +(element example + (make sequence + (make element gi: "TABLE" + attributes: (list + (list "WIDTH" "100%") + (list "BORDER" "0") + (list "CELLPADDING" "0") + (list "CELLSPACING" "0") + (list "CLASS" "EXAMPLE")) + (make element gi: "TR" + (make element gi: "TD" + ($formal-object$)))))) + + +;; Prosessing tasks for the frontpage (mode book-titlepage-recto-mode (element authorgroup (process-children)) - + (element author (let ((author-name (author-string)) (author-affil (select-elements (children (current-node)) @@ -343,40 +189,63 @@ attributes: (list (list "CLASS" (gi))) (literal author-name)) (process-node-list author-affil)))) - ) -(define (chunk-element-list) - (list (normalize "preface") - (normalize "chapter") - (normalize "appendix") - (normalize "article") - (normalize "glossary") - (normalize "bibliography") - (normalize "index") - (normalize "colophon") - (normalize "setindex") - (normalize "reference") - (normalize "refentry") - (normalize "part") - (normalize "sect1") - (normalize "sect2") - (normalize "section") - (normalize "book") ;; just in case nothing else matches... - (normalize "set") ;; sets are definitely chunks... - )) - -(define ($section-body$) - (make element gi: "DIV" - attributes: (list (list "CLASS" (gi))) - ($section-separator$) - ($section-title$) - - (if (or (not (node-list-empty? (select-elements (children (current-node)) - (normalize "sect2")))) - (not (node-list-empty? (select-elements (children (current-node)) - (normalize "sect3"))))) - (build-toc (current-node) 1) + (element editor + (let ((editor-name (author-string))) + (make sequence + (if (first-sibling?) + (make element gi: "H2" + attributes: (list (list "CLASS" "EDITEDBY")) + (literal (gentext-edited-by))) (empty-sosofo)) + (make element gi: "DIV" + attributes: (list (list "CLASS" (gi))) + (literal editor-name))))) +) - (process-children))) +;; Display of question tags, link targets +(element question + (let* ((chlist (children (current-node))) + (firstch (node-list-first chlist)) + (restch (node-list-rest chlist))) + (make element gi: "B" + (make element gi: "DIV" + attributes: (list (list "CLASS" (gi))) + (make element gi: "P" + (make element gi: "A" + attributes: (list (list "NAME" (element-id))) + (empty-sosofo)) + (make element gi: "B" + (literal (question-answer-label (current-node)) " ")) + (process-node-list (children firstch))) + (process-node-list restch)))) ) +;; Adding class HTML parameter to examples +;; having a role parameter, to make PHP examples +;; distinguisable from other ones in the manual +(define ($verbatim-display$ indent line-numbers?) + (let ( +(content (make element gi: "PRE" + attributes: (list + (list "CLASS" (if (attribute-string (normalize "role")) + (attribute-string (normalize "role")) + (gi)))) + (if (or indent line-numbers?) + ($verbatim-line-by-line$ indent line-numbers?) + (process-children-trim))))) + (if %shade-verbatim% +(make element gi: "TABLE" + attributes: (list + (list "BORDER" "0") + (list "BGCOLOR" "#E0E0E0") + (list "CELLPADDING" "5") + ) + (make element gi: "TR" + (make element gi: "TD" + content))) +(make sequence + (para-check) + content + (para-check 'restart))))) + +(define (linebreak) (make element gi: "BR" (empty-sosofo))) diff --git a/docs/en/bookinfo.xml b/docs/en/bookinfo.xml index 06d8c55e..bf4a24de 100755 --- a/docs/en/bookinfo.xml +++ b/docs/en/bookinfo.xml @@ -12,10 +12,7 @@ &build-date; - 2001 - 2002 - 2003 - 2004 + 2001-2004 ispi of Lincoln, Inc. diff --git a/docs/scripts/html_syntax.php b/docs/scripts/html_syntax.php new file mode 100755 index 00000000..49e90aa0 --- /dev/null +++ b/docs/scripts/html_syntax.php @@ -0,0 +1,71 @@ + | + | Nuno Lopes | + +----------------------------------------------------------------------+ + | Highlight PHP examples | + +----------------------------------------------------------------------+ + + $Id$ +*/ + +if ($_SERVER["argc"] < 3) { + exit("Purpose: Syntax highlight PHP examples in DSSSL generated HTML manual.\n" + .'Usage: html_syntax.php [ "html" | "php" ] [ filename.ext | dir | wildcard ] ...' ."\n" + .'"html" - highlight_string() is applied, "php" - highlight_php() is added' ."\n" + ); +} +set_time_limit(5*60); // can run long, but not more than 5 minutes + +function callback_html_number_entities_decode($matches) { + return chr($matches[1]); +} + +function callback_highlight_php($matches) { + $with_tags = preg_replace_callback("!&#([0-9]+);!", "callback_html_number_entities_decode", $matches[1]); + if ($GLOBALS["TYPE"] == "php") { + return "\n\n"; + } else { // "html" + return highlight_string($with_tags, true); + } +} + +$files = $_SERVER["argv"]; +array_shift($files); // $argv[0] - script filename +$TYPE = array_shift($files); // "html" or "php" +while (($file = array_shift($files)) !== null) { + if (is_file($file)) { + $process = array($file); + } elseif (is_dir($file)) { + $lastchar = substr($file, -1); + $process = glob($file . ($lastchar == "/" || $lastchar == "\\" ? "*" : "/*")); + } else { // should be wildcard + $process = glob($file); + } + foreach ($process as $filename) { + if (!is_file($filename)) { // do not recurse + continue; + } + $original = file_get_contents($filename); + $highlighted = preg_replace_callback("!(.*)!sU", "callback_highlight_php", $original); + if ($original != $highlighted) { + $fp = fopen($filename, "w"); + fwrite($fp, $highlighted); + fclose($fp); + } + } +} +?>