(* Input Types *) include "../../web/siteTypes.cd";; (* Output Types *) include "fo_dtd.cd";; (* Heading numbering *) type heading = [Int heading?] let heading2string (heading -> [PCDATA]) | [x] -> string_of x | [x h] -> [!(string_of x) '.' ;(heading2string h)] let incHeading (heading -> heading) | [x] -> [(x + 1)] | [x h] -> [x (incHeading h)] let newHLevel (heading -> heading) | [x] -> [x [0]] | [x h] -> [x (newHLevel h)] (* Table of contents *) type Entry = [Entry*] | [Entry*] let local_toc = ref [Entry?] [] let new_entry_toc (nid : String , ntitle : String , nhead : heading) : Entry = [] let new_entry_page_toc (nid : String , ntitle : String , nhead : heading) : Entry = [] let add_entry_toc (toc : [Entry?] , new : [Entry?]) : [Entry?] = match toc with | [] -> new | [l] -> [[!l !new]] | [l] -> [[!l !new]] let toc_entry2fo ([Entry*] -> [block*]) x -> transform x with | le -> [[ !(heading2string thead) ' ' tt ' ' [] ] !(toc_entry2fo le) ] | le -> [[ !(heading2string thead) ' ' tt ' ' [] ] !(toc_entry2fo le) ] let toc_entry2fo_table ([Entry+] -> [table-row+] ; [] -> []) x -> transform x with | le ->[ [ [ [ !(heading2string thead) ' ' ] ] [ [ tt ] ] [ [ [] ] ] ] !(toc_entry2fo_table le) ] | le ->[ [ [ [ !(heading2string thead) ' ' ] ] [ [ tt ] ] [ [ [] ] ] ] !(toc_entry2fo_table le) ] let toc_entry2pdfoutline ([Entry*] -> [fox:outline*]) x -> transform x with | <(`entry|`entry_page) toc_id=tid toc_title=tt toc_head=thead>le -> [[ [!(heading2string thead) ' ' !tt ' '] !(toc_entry2pdfoutline le) ] ] let out_global_toc (toc : [Entry?]) : [block*] = [ [] "Table of Contents" !(toc_entry2fo toc) ] let out_global_toc_table ([Entry] -> [block] ; [] -> []) | [] -> [] | toc & [Entry] -> [ [ [] "Table of Contents :" [ [] [] [] [!(toc_entry2fo_table toc)] ] ] ] (** Command line **) (* Highlighting text between {{...}} *) let highlight (String -> [ (Char| inline)* ] ) | [ '{{%%' h ::(Char *?) '%%}}' ; rest ] -> [ h; highlight rest] | [ '{{' h ::(Char *?) '}}' ; rest ] -> [ h; highlight rest] | [ '$$%%' h ::(Char *?) '%%$$' ; rest ] -> [ h; highlight rest] | [ '$$' h ::(Char *?) '$$' ; rest ] -> [ h; highlight rest] | [ '%%' h ::(Char *?) '%%' ; rest ] -> [ h; highlight rest] | [ c ; rest ] -> [c ; highlight rest] | [] -> [] let text (t : [InlineText*]) : [(block|basic-link|Char|inline|list-block|footnote|table)*] = transform t with |s2 ->[[!(text s2)]] |s2 -> [[!(text s2)]] |s2 -> [[!(text s2)]] |s2 -> [[!(text s2)]] | z & Char -> [z] | x -> [[ !(highlight x)] ] | (s2&[InlineText*]) ->[ [!(text s2)]] | (s2&[InlineText*]) (* if it starts by # is an internal reference *) ->[ [!(text s2)]] | (s2&[InlineText*]) (* otherwise it is an external reference *) ->[ [!(text s2)]] |t -> [ [ "(*)" [ [ [ [ "(*)"] [ [!(text t)]]]]]]] let content (t : Content) : [(block|basic-link|Char|inline|list-block|footnote|table)*] = transform t with |
c -> [[ [!title1] !(content c) ]] |((s) | s) -> [[!(highlight s)]] |((s) | s) -> [[!(highlight s)]] | ((s) | s) -> [[!(highlight s)]] |

x -> [[!(text x)]] | [ (col:: H.col)* (rows::H.tr)+] -> [[ !(map col with [] -> []) ( transform rows with y -> [( transform y with |
(z&Content) -> [[ [!(content z) ]]] | (z&Content) -> [[ [!(content z) ]]] | (z&Content) -> [[ [!(content z) ]]] (* fake entry to assure that it will have type table-cell+*) | _ -> [[[]]] )]) ]] |
    u ->[ ( transform u with
  • c -> [[ [ "\x2022;"] [ [ !(content c) ]]]])] |
      o -> [ ( let i = ref Int 0 in transform o with
    1. c -> [[ [ (string_of(i:=!i+1 ; !i)@".")] [ [ !(content c) ]]]])] | p & Paper -> (paper p) | l & Link -> (link l) | s & Slides -> (slides s) | i & InlineText -> (text [i]) | s -> [[("Note: ") !(content s)]] | [ x y ] -> [[ [] [] [ [ [[!(content x)]] [[!(content y)]]]]]] | _ ->[['TODO PAGES TABLE OF CONTENTS']] | _ -> [['TODO SITE TABLE OF CONTENTS']] | _ -> [['A FAIRE LOCAL LINKS']] | _ -> [['A FAIRE FOOTNOTE']] | _ -> [['A FAIRE DEMO LABEL']] | _ -> [] let paper (p : Paper) : [block*] = match p with _ -> [['A FAIRE PAPER']] let link (l : Link) : [block*] = match l with _ -> [['A FAIRE LINK']] let slides (s : Slides) : [block*] = match s with _ -> [['A FAIRE SLIDE']] let readItem (it : [Item+]): [block*] = transform it with | c -> [[ [[!t]] !(content c)]] | c -> [[!(content c)]] | c -> (* non utilise pour manuel et tutoriel*) [[!(content c)]] | _ -> [[]] | [] -> [[ ]] | [(_) (<banner>_)? ] -> [<fo:block>['box vide!!!!!!!!!!!!!']] | <page name=x >[(<title>title1 (<banner>_)? litem::Item+)] -> [<fo:block id=x break-before="page" text-align-last="justify">[ <fo:block text-align="left">[ <fo:block font-size="32pt" font-weight="bold" space-after="40pt" space-before="85pt" color="black" >[!title1] ] !(readItem litem) ]] | _ -> raise "ERROR" (* adding heading numbering ... *) let readItemHead (([Item+],heading) -> [block*]) (it,head) -> let href = ref heading head in transform it with | <box title=t link=x>c -> let _ = href := incHeading !href in let box_entry = new_entry_toc (x,t,!href) in let saved_toc = !local_toc in let _ = local_toc := [box_entry] in let result = [<fo:block id=x>[ <fo:block font-size="22pt" space-before="15pt">[ <fo:block space-after="7pt" font-weight="bold">[!(heading2string !href) ' ' !t]] !(content c) ] ] in let new_toc = add_entry_toc (saved_toc,!local_toc) in local_toc := new_toc ; result | <box>c -> [<fo:block>[!(content c)]] | <meta>c -> (* non utilise pour manuel et tutoriel*) [<fo:block>[!(content c)]] | <left>_ -> [<fo:block>[]] | <footnotes>[] -> [<fo:block>[ ]] | <page .. > [(<title>_) (<banner>_)? ] -> [<fo:block>['box vide!!!!!!!!!!!!!']] | <page name=x >[(<title>title1 (<banner>_)? litem::Item+)] -> let _ = href := incHeading !href in let box_entry = new_entry_page_toc (x,title1,!href) in let saved_toc = !local_toc in let _ = local_toc := [box_entry] in let result = [<fo:block id=x break-before="page" text-align-last="justify">[ <fo:block text-align="left">[ <fo:block font-size="32pt" font-weight="bold" space-after="40pt" space-before="85pt" color="black" >[ !(heading2string !href) ' ' !title1 ] ] !(readItemHead (litem,newHLevel !href)) ] ] in let new_toc = add_entry_toc (saved_toc,!local_toc) in local_toc := new_toc ; result | _ -> raise "ERROR" let gen_page (page : Page, cduce_version : Latin1) : [block+] = match page with (* le cas sans item*) <page ..>[(<title>_) (<banner>_)?] -> [<fo:block text-align="center" font-size="35pt" color="green" space-after="30pt"> (raise "error") ] (* la cas de base *) |<page ..>[(<title>title1 (<banner>_)? litem::Item+)] ->( let sortie : [block+]= [ <fo:block text-align="center" space-before="130pt">[ <fo:block font-size="35pt" font-weight="bold">"CDuce Programming Language" <fo:block font-size="35pt" font-weight="bold" space-after="20pt">[!title1] <fo:block font-size="18pt" font-weight="bold">("Language Version "@cduce_version) ] !(readItem litem)] in sortie) (* adding heading numbering *) let gen_pageHead (page : Page, cduce_version : Latin1) : [block+] = match page with (* le cas sans item*) <page ..>[(<title>_) (<banner>_)?] -> [<fo:block text-align="center" font-size="35pt" color="green" space-after="30pt"> (raise "error") ] (* la cas de base *) |<page ..>[(<title>title1 (<banner>_)? litem::Item+)] -> ( let head = <heading>[0] in let rIH = (readItemHead (litem, head)) in let sortie : [ block+ ]= [ <fo:block text-align="center" space-before="80pt">[ <fo:block font-size="35pt" font-weight="bold" space-before="30pt">"CDuce Programming Language" <fo:block font-size="35pt" font-weight="bold" space-after="20pt">[!title1] <fo:block font-size="18pt" font-weight="bold">("Language Version "@cduce_version) <fo:external-graphic src="url(../../web/img/cduce_logo.jpg)">[] ] !(out_global_toc_table !local_toc) (* !(out_global_toc !local_toc) *) !rIH ] in sortie) let load_include (Latin1 -> [Any*]) name -> xtransform [ (load_xml name) ] with | <include file=(s & Latin1)>[] -> load_include s | <include-verbatim file=(s & Latin1)>[] -> load_file s in match argv [] with | [ (inp_file & Latin1) (out_file & Latin1) (cduce_version & Latin1) ] -> (try let ([ main_page ]) = (load_include inp_file :? [ Page ]) in let content = (gen_pageHead(main_page,cduce_version)) in let DebutFo : root = <fo:root >[ <fox:outline internal-destination="toc-main">[<fox:label>("Table of Contents")] !(toc_entry2pdfoutline !local_toc) <fo:layout-master-set>[ <fo:simple-page-master master-name="essai" page-height="29.7cm" page-width="21cm">[ <fo:region-body margin-top="3cm" margin-bottom="3.5cm" margin-left="2.5cm" margin-right="2.5cm">[] <fo:region-after region-name="footer" extent="15mm">[] ] ] <fo:page-sequence initial-page-number="auto" master-reference="essai" >[ <fo:static-content flow-name="xsl-footnote-separator">[ <fo:block>[ <fo:leader leader-pattern="rule" leader-length="100%" rule-style="solid" rule-thickness="0.5pt">[] ] ] <fo:static-content flow-name="footer">[ <fo:block text-align="center">[ <fo:page-number>[] ] ] <fo:flow flow-name="xsl-region-body" font-size="12pt" text-align="justify"> [!content] ] ] in dump_to_file ("../doc/fomanual/"@out_file) (* dump_to_file (out_file) *) ['<?xml version="1.0" encoding="ISO-8859-1"?>' !(print_xml DebutFo)] (*print(print_xml(main_page));*) (* print (gen_page main_page)*) with err & Latin1 -> print ['Invalid input document\n' !err '\n']; exit 2 ) | _ -> raise "Wrong argument number or type: please correct the --arg option";;