ussg

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit 5b990e210b16cb952f5112fdd44bd416cb63a16f
Author: Ellenor Bjornsdottir <ellenor@umbrellix.net>
Date:   Mon, 12 Sep 2022 07:28:09 +0000

Initial commit, after scribbling out the whole repository earlier

Diffstat:
A.gitignore | 0
ALICENCE.md | 230+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
AMakefile | 0
AREADME.md | 14++++++++++++++
Adoc/examples/page.tpl | 0
Adoc/interface.md | 36++++++++++++++++++++++++++++++++++++
Aussg-page | 287+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
7 files changed, 567 insertions(+), 0 deletions(-)

diff --git a/.gitignore b/.gitignore diff --git a/LICENCE.md b/LICENCE.md @@ -0,0 +1,230 @@ +Copyright 2021 Umbrellix <ellenor@umbrellix.net>. All Rights Reserved. + +Your licence to this software is governed under the laws of BC, Canada, except as required by +applicable laws where you may reside. + +This is software, and it is NOT Open Source software, +per https://opensource.org/faq#avoid-unapproved-licenses . + +The source is available to you and your assigns provided that you and they follow the terms below. +If they are onerous, speak to the Initial Developer(s) and the Contributor(s) and/or their heirs or +assigns, and you may be able to obtain special dispensation to use and redistribute the software +under other licence terms. + +You should have received a copy of the Umbrellix Softare Licence, or other special licence you may +have negotiated, with this programme. If you haven't, please retrieve the CDDL-1.0 (on which the USL +is based): +https://opensource.org/licenses/cddl1.txt and prepend: + +Appendix 1. +USL replaces Section 4.1 with the following text: +Ellenor Agnes Bjornsdottir, or any person, natural or legal, she may with notice to initial licencees +assign the status to, is the licence steward and may, from time to time, publish revised and/or new +versions of this licence. Each version will be given a distinguishing version number, which may +be a commit number from a version control system. This licence may be modified solely as provided by +section 4.3. + +Appendix 2. +USL renumbers Section 4.3 to Section 4.3.1. +USL adds a Section 4.3.2, entitled "This licence is not the Sun CDDL", with the following text. +The terms of the USL are not those of the CDDL as published by Sun Microsystems, Inc. and +its heirs, assigns and successors. The terms of the USL are substantively different from the CDDL's, +and combination of the two licences in a larger work may result in a work that is not distributable. + +Appendix 3. +USL renumbers Section 6.1 to Section 6.1.1. +USL adds a Section 6.1.2, entitled "Resumability", with the following text. +This licence, and the rights previously granted under this licence, will resume automatically should You +wholly cure a breach of the licence that results in termination under section 6.1.1. You remain liable for +damages incurred by the initial developer or any contributor as a result of the breach. + +Appendix 4. +USL appends the following text to 1.4. +In the case of Covered Software which is not software, the Executable is the final form in which the +Covered Software is intended to be consumed. (Non-legal readers: think of a releasable piece of music, +regardless of how it's encoded) + +Appendix 5. +USL appends the following text to 1.12. +In the case of Covered Software which is not software, the Source Code is the data from which the +Executable is generated. (Non-legal readers: think of a piano roll in a DAW.) + +Appendix 6. +USL replaces the following text from Section 9: + This Licence shall be governed by the law of the jurisdiction specified in a notice contained within + the Original Software (except to the extent applicable law, if any, provides otherwise), excluding + such jurisdiction's conflict-of-law provisions. Any litigation relating to this Licence shall be + subject to the jurisdiction of the courts located in the jurisdiction and venue specified in a + notice contained within the Original Software, with the losing party responsible for costs, including, + without limitation, court costs and reasonable attorneys' fees and expenses. The application of the + United Nations Convention on Contracts for the International Sale of Goods is expressly excluded. +with the following text: + This Licence shall be governed by the law of the jurisdiction specified in a notice contained within + the Original Software (except to the extent applicable law, if any, provides otherwise), INCLUDING + such jurisdiction's conflict-of-law provisions. The application of the United Nations Convention + on Contracts for the International Sale of Goods is not limited by this section. Should there be no + jurisdiction notice included with the Original Software, or should it be waived by the initial + developer(s), You may opt that the licence be governed under the law of the jurisdiction in which + You reside. + +Appendix 7. +USL changes Section 1.10 to add: + , or other covered works, +after the words + "computer software code." + +The USL, as amended, is reproduced below. + +This is the Umbrellix Software Licence (USL), version 0.1. +This is NOT the COMMON DEVELOPMENT AND DISTRIBUTION LICENSE (CDDL) Version 1.0 on which it is based. + +1. Definitions. + +1.1. "Contributor" means each individual or entity that creates or contributes to the creation of Modifications. + +1.2. "Contributor Version" means the combination of the Original Software, prior Modifications used by a Contributor (if any), and the Modifications made by that particular Contributor. + +1.3. "Covered Software" means (a) the Original Software, or (b) Modifications, or (c) the combination of files containing Original Software with files containing Modifications, in each case including portions thereof. + +1.4. "Executable" means the Covered Software in any form other than Source Code. In the case of Covered Software which is not software, the Executable is the final form in which the Covered Software is intended to be consumed. (Non-legal readers: think of a releasable piece of music, regardless of how it's encoded) + +1.5. "Initial Developer" means the individual or entity that first makes Original Software available under this License. + +1.6. "Larger Work" means a work which combines Covered Software or portions thereof with code not governed by the terms of this License. + +1.7. "License" means this document. + +1.8. "Licensable" means having the right to grant, to the maximum extent possible, whether at the time of the initial grant or subsequently acquired, any and all of the rights conveyed herein. + +1.9. "Modifications" means the Source Code and Executable form of any of the following: + +A. Any file that results from an addition to, deletion from or modification of the contents of a file containing Original Software or previous Modifications; + +B. Any new file that contains any part of the Original Software or previous Modification; or + +C. Any new file that is contributed or otherwise made available under the terms of this License. + +1.10. "Original Software" means the Source Code and Executable form of computer software code, or other covered works, that is originally released under this License. + +1.11. "Patent Claims" means any patent claim(s), now owned or hereafter acquired, including without limitation, method, process, and apparatus claims, in any patent Licensable by grantor. + +1.12. "Source Code" means (a) the common form of computer software code in which modifications are made and (b) associated documentation included in or with such code. In the case of Covered Software which is not software, the Source Code is the data from which the Executable is generated. (Non-legal readers: think of a piano roll in a DAW.) + +1.13. "You" (or "Your") means an individual or a legal entity exercising rights under, and complying with all of the terms of, this License. For legal entities, "You" includes any entity which controls, is controlled by, or is under common control with You. For purposes of this definition, "control" means (a) the power, direct or indirect, to cause the direction or management of such entity, whether by contract or otherwise, or (b) ownership of more than fifty percent (50%) of the outstanding shares or beneficial ownership of such entity. + +2. License Grants. + +2.1. The Initial Developer Grant. + +Conditioned upon Your compliance with Section 3.1 below and subject to third party intellectual property claims, the Initial Developer hereby grants You a world-wide, royalty-free, non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) Licensable by Initial Developer, to use, reproduce, modify, display, perform, sublicense and distribute the Original Software (or portions thereof), with or without Modifications, and/or as part of a Larger Work; and + +(b) under Patent Claims infringed by the making, using or selling of Original Software, to make, have made, use, practice, sell, and offer for sale, and/or otherwise dispose of the Original Software (or portions thereof). + +(c) The licenses granted in Sections 2.1(a) and (b) are effective on the date Initial Developer first distributes or otherwise makes the Original Software available to a third party under the terms of this License. + +(d) Notwithstanding Section 2.1(b) above, no patent license is granted: (1) for code that You delete from the Original Software, or (2) for infringements caused by: (i) the modification of the Original Software, or (ii) the combination of the Original Software with other software or devices. + +2.2. Contributor Grant. + +Conditioned upon Your compliance with Section 3.1 below and +subject to third party intellectual property claims, each +Contributor hereby grants You a world-wide, royalty-free, +non-exclusive license: + +(a) under intellectual property rights (other than patent or trademark) Licensable by Contributor to use, reproduce, modify, display, perform, sublicense and distribute the Modifications created by such Contributor (or portions thereof), either on an unmodified basis, with other Modifications, as Covered Software and/or as part of a Larger Work; and + +(b) under Patent Claims infringed by the making, using, or selling of Modifications made by that Contributor either alone and/or in combination with its Contributor Version (or portions of such combination), to make, use, sell, offer for sale, have made, and/or otherwise dispose of: (1) Modifications made by that Contributor (or portions thereof); and (2) the combination of Modifications made by that Contributor with its Contributor Version (or portions of such combination). + +(c) The licenses granted in Sections 2.2(a) and 2.2(b) are effective on the date Contributor first distributes or otherwise makes the Modifications available to a third party. +(d) Notwithstanding Section 2.2(b) above, no patent license is granted: (1) for any code that Contributor has deleted from the Contributor Version; (2) for infringements caused by: (i) third party modifications of Contributor Version, or (ii) the combination of Modifications made by that Contributor with other software (except as part of the Contributor Version) or other devices; or (3) under Patent Claims infringed by Covered Software in the absence of Modifications made by that Contributor. + +3. Distribution Obligations. + +3.1. Availability of Source Code. + +Any Covered Software that You distribute or otherwise make available in Executable form must also be made available in Source Code form and that Source Code form must be distributed only under the terms of this License. You must include a copy of this License with every copy of the Source Code form of the Covered Software You distribute or otherwise make available. You must inform recipients of any such Covered Software in Executable form as to how they can obtain such Covered Software in Source Code form in a reasonable manner on or through a medium customarily used for software exchange. + +3.2. Modifications. + +The Modifications that You create or to which You contribute are governed by the terms of this License. You represent that You believe Your Modifications are Your original creation(s) and/or You have sufficient rights to grant the rights conveyed by this License. + +3.3. Required Notices. + +You must include a notice in each of Your Modifications that identifies You as the Contributor of the Modification. You may not remove or alter any copyright, patent or trademark notices contained within the Covered Software, or any notices of licensing or any descriptive text giving attribution to any Contributor or the Initial Developer. + +3.4. Application of Additional Terms. + +You may not offer or impose any terms on any Covered Software in Source Code form that alters or restricts the applicable version of this License or the recipients' rights hereunder. You may choose to offer, and to charge a fee for, warranty, support, indemnity or liability obligations to one or more recipients of Covered Software. However, you may do so only on Your own behalf, and not on behalf of the Initial Developer or any Contributor. You must make it absolutely clear that any such warranty, support, indemnity or liability obligation is offered by You alone, and You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of warranty, support, indemnity or liability terms You offer. + +3.5. Distribution of Executable Versions. + +You may distribute the Executable form of the Covered Software under the terms of this License or under the terms of a license of Your choice, which may contain terms different from this License, provided that You are in compliance with the terms of this License and that the license for the Executable form does not attempt to limit or alter the recipient's rights in the Source Code form from the rights set forth in this License. If You distribute the Covered Software in Executable form under a different license, You must make it absolutely clear that any terms which differ from this License are offered by You alone, not by the Initial Developer or Contributor. You hereby agree to indemnify the Initial Developer and every Contributor for any liability incurred by the Initial Developer or such Contributor as a result of any such terms You offer. + +3.6. Larger Works. + +You may create a Larger Work by combining Covered Software with other code not governed by the terms of this License and distribute the Larger Work as a single product. In such a case, You must make sure the requirements of this License are fulfilled for the Covered Software. + +4. Versions of the License. + +4.1. New Versions. + +Ellenor Agnes Bjornsdottir, or any person, natural or legal, she may with notice to initial licencees assign the status to, is the licence steward and may, from time to time, publish revised and/or new +versions of this licence. Each version will be given a distinguishing version number, which may be a commit number from a version control system. This licence may be modified solely as provided by section 4.3. + +(In the original text, this section had read as follows: Sun Microsystems, Inc. is the initial license steward and may publish revised and/or new versions of this License from time to time. Each version will be given a distinguishing version number. Except as provided in Section 4.3, no one other than the license steward has the right to modify this License.) + +4.2. Effect of New Versions. + +You may always continue to use, distribute or otherwise make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. If the Initial Developer includes a notice in the Original Software prohibiting it from being distributed or otherwise made available under any subsequent version of the License, You must distribute and make the Covered Software available under the terms of the version of the License under which You originally received the Covered Software. Otherwise, You may also choose to use, distribute or otherwise make the Covered Software available under the terms of any subsequent version of the License published by the license steward. + +4.3. Modified Versions. + +4.3.1. Modified Versions. + +When You are an Initial Developer and You want to create a new license for Your Original Software, You may create and use a modified version of this License if You: (a) rename the license and remove any references to the name of the license steward (except to note that the license differs from this License); and (b) otherwise make it clear that the license contains terms which differ from this License. + +4.3.2. This licence is not the Sun CDDL + +The terms of the USL are not those of the CDDL as published by Sun Microsystems, Inc. and its heirs, assigns and successors. The terms of the USL are substantively different from the CDDL's, and combination of the two licences in a larger work may result in a work that is not distributable. + +5. DISCLAIMER OF WARRANTY. + +COVERED SOFTWARE IS PROVIDED UNDER THIS LICENSE ON AN "AS IS" BASIS, WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, WITHOUT LIMITATION, WARRANTIES THAT THE COVERED SOFTWARE IS FREE OF DEFECTS, MERCHANTABLE, FIT FOR A PARTICULAR PURPOSE OR NON-INFRINGING. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE COVERED SOFTWARE IS WITH YOU. SHOULD ANY COVERED SOFTWARE PROVE DEFECTIVE IN ANY RESPECT, YOU (NOT THE INITIAL DEVELOPER OR ANY OTHER CONTRIBUTOR) ASSUME THE COST OF ANY NECESSARY SERVICING, REPAIR OR CORRECTION. THIS DISCLAIMER OF WARRANTY CONSTITUTES AN ESSENTIAL PART OF THIS LICENSE. NO USE OF ANY COVERED SOFTWARE IS AUTHORIZED HEREUNDER EXCEPT UNDER THIS DISCLAIMER. + +6. TERMINATION. + +6.1. Termination upon violation, resumption upon cure + +6.1.1. Termination upon violation + +This License and the rights granted hereunder will terminate automatically if You fail to comply with terms herein and fail to cure such breach within 30 days of becoming aware of the breach. Provisions which, by their nature, must remain in effect beyond the termination of this License shall survive. + +6.1.2. Resumption upon cure + +This licence, and the rights previously granted under this licence, will resume automatically should You wholly cure a breach of the licence that results in termination under section 6.1.1. You remain liable for damages incurred by the initial developer or any contributor as a result of the breach. + +6.2. If You assert a patent infringement claim (excluding declaratory judgment actions) against Initial Developer or a Contributor (the Initial Developer or Contributor against whom You assert such claim is referred to as "Participant") alleging that the Participant Software (meaning the Contributor Version where the Participant is a Contributor or the Original Software where the Participant is the Initial Developer) directly or indirectly infringes any patent, then any and all rights granted directly or indirectly to You by such Participant, the Initial Developer (if the Initial Developer is not the Participant) and all Contributors under Sections 2.1 and/or 2.2 of this License shall, upon 60 days notice from Participant terminate prospectively and automatically at the expiration of such 60 day notice period, unless if within such 60 day period You withdraw Your claim with respect to the Participant Software against such Participant either unilaterally or pursuant to a written agreement with Participant. + +6.3. In the event of termination under Sections 6.1 or 6.2 above, all end user licenses that have been validly granted by You or any distributor hereunder prior to termination (excluding licenses granted to You by any distributor) shall survive termination. + +7. LIMITATION OF LIABILITY. + +UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, WHETHER TORT (INCLUDING NEGLIGENCE), CONTRACT, OR OTHERWISE, SHALL YOU, THE INITIAL DEVELOPER, ANY OTHER CONTRIBUTOR, OR ANY DISTRIBUTOR OF COVERED SOFTWARE, OR ANY SUPPLIER OF ANY OF SUCH PARTIES, BE LIABLE TO ANY PERSON FOR ANY INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES OF ANY CHARACTER INCLUDING, WITHOUT LIMITATION, DAMAGES FOR LOST PROFITS, LOSS OF GOODWILL, WORK STOPPAGE, COMPUTER FAILURE OR MALFUNCTION, OR ANY AND ALL OTHER COMMERCIAL DAMAGES OR LOSSES, EVEN IF SUCH PARTY SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF SUCH DAMAGES. THIS LIMITATION OF LIABILITY SHALL NOT APPLY TO LIABILITY FOR DEATH OR PERSONAL INJURY RESULTING FROM SUCH PARTY'S NEGLIGENCE TO THE EXTENT APPLICABLE LAW PROHIBITS SUCH LIMITATION. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION OR LIMITATION OF INCIDENTAL OR CONSEQUENTIAL DAMAGES, SO THIS EXCLUSION AND LIMITATION MAY NOT APPLY TO YOU. + +8. U.S. GOVERNMENT END USERS. + +The Covered Software is a "commercial item," as that term is defined in 48 C.F.R. 2.101 (Oct. 1995), consisting of "commercial computer software" (as that term is defined at 48 C.F.R. ¤ 252.227-7014(a)(1)) and "commercial computer software documentation" as such terms are used in 48 C.F.R. 12.212 (Sept. 1995). Consistent with 48 C.F.R. 12.212 and 48 C.F.R. 227.7202-1 through 227.7202-4 (June 1995), all U.S. Government End Users acquire Covered Software with only those rights set forth herein. This U.S. Government Rights clause is in lieu of, and supersedes, any other FAR, DFAR, or other clause or provision that addresses Government rights in computer software under this License. + +9. MISCELLANEOUS. + +This License represents the complete agreement concerning subject matter hereof. If any provision of this License is held to be unenforceable, such provision shall be reformed only to the extent necessary to make it enforceable. + +This Licence shall be governed by the law of the jurisdiction specified in a notice contained within the Original Software (except to the extent applicable law, if any, provides otherwise), INCLUDING such jurisdiction's conflict-of-law provisions. The application of the United Nations Convention on Contracts for the International Sale of Goods is not limited by this section. Should there be no jurisdiction notice included with the Original Software, or should it be waived by the initial developer(s), You may opt that the licence be governed under the law of the jurisdiction in which You reside. + +Any law or regulation which provides that the language of a contract shall be construed against the drafter shall not apply to this License. You agree that You alone are responsible for compliance with the United States export administration regulations (and the export control laws and regulation of any other countries) when You use, distribute or otherwise make available any Covered Software. + +10. RESPONSIBILITY FOR CLAIMS. + +As between Initial Developer and the Contributors, each party is responsible for claims and damages arising, directly or indirectly, out of its utilization of rights under this License and You agree to work with Initial Developer and Contributors to distribute such responsibility on an equitable basis. Nothing herein is intended or shall be deemed to constitute any admission of liability. diff --git a/Makefile b/Makefile diff --git a/README.md b/README.md @@ -0,0 +1,14 @@ + +# Umbrellix SSG + +That's not its permanent name, just a temporary name while we (the Bjornsdottirs and [Lightning](https://chatspeed.net./)) instate the permanent name. + +## Utilities + +This project contains only one utility. Its name, currently, is ussg-page. + + * [ussg-page interface notes] + +## Dependencies + +This project depends on a converter program, archetypally `markdown`, but can be any that produces fragmentary HTML like `markdown` does. diff --git a/doc/examples/page.tpl b/doc/examples/page.tpl diff --git a/doc/interface.md b/doc/interface.md @@ -0,0 +1,36 @@ +X-Site-Title: Umbrellix +X-Site-Description: Left politics, programming, and self-hosted Internet services: experiences, lessons and hope +X-Synoptic-Title: Interface of ussg +X-Synoptic-Text: ussg thus far carries one utility. Its interface is described in page. + +# Interface of the utility + +The main-stream input format of ussg is modified Markdown. The modification is that headers, à la email message headers, are added previous to the markdown text, separated from the Markdown text by two _system linefeed_ (that is, LF on UNIX, and CR,LF on MS-DOS and Windows. Unknown as to what it is on Plan 9) instances. This is inserted as article text. Your Markdown implementation will govern other details. I prefer ['discount' de gh:Orc](https://github.com/Orc/discount). + +The first side-stream input format of ussg is the ussg headers only. These can be stored in a file with an arbitrary name. On UNIX, to "hide" the file from regular viewing in directory listings, it may start with a full stop. This doesn't bear on how ussg uses it. + +Headers in the main-stream override single-use headers of the same name in the first side-stream. The first side-stream is read before the main-stream headers. + +The second side-stream input format of ussg is template, tbd. + +The third etc. side-stream input formats of ussg is HTML. These are printed verbatim to the output file in their template-appropriate locations, and the recommended template (which also includes some verbatim HTML5) has 4 such positions. These side-stream inputs are pointed to from headers. + +The names and purposes of the headers are thus: + +Name|Type|Purpose +-|-|- +Title|Once|Set head::title +X-Site-Title|Once|Set site title (shown between header nav, and opt sidebar nav) +X-Site-Description|Once|Set site subtitle +X-Synoptic-Title|Once|Set meta og:title (synoptic title of the content) +X-Synoptic-Text|Once|Set meta og:description (synoptic description of the content) +Favicon|Once|Favicon +Template|Once|Template +Style|inf times|CSS style, relative to the webpage +Verbatim|n times|HTML printed verbatim where the Template requests %n + +The invokation of the utility is thus (program name subject to change): + +`ussg-page [-hv] [-H headers] input [output]` + +It is meant to be invoked from a makefile, and its output, if on standard output, is supposed to be redirected to a temporary file, then moved atomically over the intended name. This is done automaticall if you use a filename output. diff --git a/ussg-page b/ussg-page @@ -0,0 +1,287 @@ +#!/usr/bin/env tclsh8.6 + +# proc until {test body} {uplevel 1 [list while [concat ! $test] $body]} + +proc opts {{consume {h v H: M: help version headers: markdown:}} argl} { + # will always output a list n=2. + # [lindex [opts ...] 0] = a list of lists: option, argument(s) + # [lindex [opts ...] 1] = a list of arguments not consumed + # loptpile contains the long options followed by the number of arguments they consume + # a : not immediately preceded by a backslash means that consumed++ + # two backslashes collapse to one. + # soptpile contains the options which are one letter (one may write -HM header markdown) + set loptpile [list] + set soptpile [list] + foreach {option} $consume { + set optname "" + set colons 0 + set prevl "" + foreach {l} [split $option {}] { + if {$l == ":" && $prevl != "\\"} {incr colons} + if {($l != "\\" || $prevl == "\\") && $colons < 1} { + append optname $l + } + if {$prevl != "\\"} {set prevl $l} {set prevl ""} + } + if {[string length $optname] > 1} {lappend loptpile $optname $colons} {lappend soptpile $optname $colons} + } + set consumingargs [list] + set consumedargs [list] + set unconsumedargs [list] + set n 0 + set dashdash 0 + while {$n < [llength $argl]} { + set arg [lindex $argl $n] + set colons 0 + if {$dashdash} { + lappend unconsumedargs $arg + } { + if {[string index $arg 0] == "-"} { + if {[string index $arg 1] == "-"} { + if {[string length $arg] == 2} {set dashdash 1} { + # long opt; consume argument immediately after, even if it starts with a dash + # if not a real opt, don't care + if {[set colons [dict get $loptpile [string range $arg 2 end]]] != ""} { + set consumedarg [list [string range $arg 2 end]] + if {$colons != 0} { + if {[llength [lrange $argl [expr {$n+1}] [expr {$n+$colons}]]] == $colons} { + lappend consumedarg [lrange $argl [expr {$n+1}] [expr {$n+$colons}]] + incr n $colons + } { + return -code error "Reached end of arguments list while consuming arguments for option $arg ([lrange $argl [expr {$n+1}] [expr {$n+$colons}]])" + } + } + lappend consumedargs $consumedarg + } { + lappend unconsumedargs $arg + } + } + } { + if {[string length $arg] == 1} {lappend unconsumedargs $arg} { + # short option + foreach {letter} [split [string range $arg 1 end] {}] { + if {[catch {dict get $soptpile $letter} colons] == 0} { + #set colons [dict get $soptpile $letter] + set consumedarg [list $letter] + if {$colons != 0} { + if {[llength [lrange $argl [expr {$n+1}] [expr {$n+$colons}]]] == $colons} { + foreach {ar} [lrange $argl [expr {$n+1}] [expr {$n+$colons}]] {lappend consumedarg $ar} + incr n $colons + } { + return -code error "Reached end of arguments list while consuming arguments for option $arg ([lrange $argl [expr {$n+1}] [expr {$n+$colons}]])" + } + } + lappend consumedargs $consumedarg + } { + # unrecognized dash option - warn user and treat as a separate non-option arg + puts stderr [format "warning: option -%s not recognized by this program. Treating as a SEPARATE non-option argument - if this wasn't intended, put the argument containing this option after a \'--\'!" $letter] + lappend unconsumedargs [join [list - $letter] {}] + } + # if there's even zero colons + } + # foreach letter + } + # if only dash + } + # if two dashes + } else { + lappend unconsumedargs $arg + } + # if one dash + } + # if dashdash + incr n + } + # while + return [list $consumedargs $unconsumedargs] +} + +set version v0.0-alpha +set programname "ussg-page page generator" + +proc printversion {} { + puts stderr [format "%s %s (Tcl)" $::programname $::version] + puts stderr {All Rights Reserved © 2022 by Ellenor Agnes Bjornsdottir +Most activity in the nature of redistributing this application, +unmodified or modified, is permitted. See LICENCE for more info. + +This program is, to the extent permitted by applicable law, supplied +with no warranty, not even the implied warranties for +merchantability or fitness for purpose. Where legally possible, my +liability at any remaining warranty claims will be limited to the +amount I received in return for you receiving this software. + +Exceptionally: +For stable releases, I warrant that the software has been +demonstrated to produce usable output on a common UNIX operating +system with Tcl 8.6, and using Orc's Discount markdown engine, +with the included input data. Your recovery is limited to damage +caused by improper operation of the software, which you did not +cause, which doesn't appear to be related to defective input +or hardware. Bug reports are welcome and are preferred over +legal process if possible. +} +} + + +set help {usage: %0 [--..] [-hv] [-H headers] [-M /usr/bin/markdown] [--] input [output] + +Generate a complete HTML page from input and headers to output. +headers and input are as described in interface.md and +ussg-page.1. + +If both input and output are blank, convert stdin to stdout. + +A double dash terminates option processing, and all arguments +are taken as non-options thereafter, including other double +dashes. + +Options: + -h, --help + Display this help. + -v, --version + Displays the version of this program. + -H/--headers [headers] + headers file, read before input. input is treated as if + it's catenated after headers. + May be specified more than once. + -M/--markdown [markdown] + 'Markdown' command line. Must accept Markdown on standard + input and produce fragmentary HTML on standard output. + Default if not specified: env markdown + -R/--restricted + Restricted mode. Does not scribble on an already existing + output file. Instead, balks with EX_CANTCREAT (73). + This is not default, but it is recommended to use this if + possible. + +Specifying multiple short options together will result in them +being interpreted separately, including dash options that +consume arguments. Unknown dash options will be treated as +non-option arguments; you will receive a warning on stderr +if this occurs. + +Example (without unknown options): + + %0 -HM .headers "$HOME/.local/src/discount/markdown [options]" + Run this program, stdin to stdout, with a headers + sidestream of .headers and a Markdown command line + of "$HOME/.local/src/discount/markdown [options]" + (with dquotes, this'll be interpreted by your shell, then + by Tcl in a usage of [open |...]) + + %0 -HM .headers "$HOME/.local/src/discount/markdown [options]" -- -malchik -zhenschina + Run this program, ./-malchik to ./-zhenschina, with a + headers sidestream of .headers and a Markdown command + line of "$HOME/.local/src/discount/markdown [options]" + (with dquotes, this'll be interpreted by your shell, then + by Tcl in a usage of [open |...]) + The etymology of the nonsense words used is Russian for + boy and woman. + +Example (with unknown options): + + %0 -HMYZ .headers "$HOME/.local/src/discount/markdown [options]" + Run this program, ./-Y to ./-Z, with a headers + sidestream of .headers and a Markdown command line + of "$HOME/.local/src/discount/markdown [options]" +Note: That's probably not what you want, and the behavior will + change if those options ever become recognized. + Do not invoke this program this way except for a joke. +} + +proc printhelp {} { + puts stderr [string map [list %0 $::argv0] $::help] +} + +set inputfd stdin +set outputfd stdout +set headersfiles [list] +set headersfds [list] +set markdown [list env markdown] +set scribble 1 + +## Begin command routine + +set parsedargs [opts [list h v H: M: help version headers: markdown:] $argv] +# opts [list h v H: M: help version headers: markdown:] [list input --markdown /usr/bin/markdown output -HMEQI .headers /usr/bin/markdown -- -EQI -- -- --] +# warning: option -E not recognized by this program. Treating as a SEPARATE non-option argument - if this wasn't intended, put the argument containing this option after a '--'! +# warning: option -Q not recognized by this program. Treating as a SEPARATE non-option argument - if this wasn't intended, put the argument containing this option after a '--'! +# warning: option -I not recognized by this program. Treating as a SEPARATE non-option argument - if this wasn't intended, put the argument containing this option after a '--'! +# {{markdown /usr/bin/markdown} {H .headers} {M /usr/bin/markdown}} {input output -E -Q -I -EQI -- -- --} + +lassign $parsedargs opts arg + +foreach {opt} $opts { + switch -exact -- [lindex $opt 0] { + h - + help { + printhelp + exit 64 + } + + v - + version { + printversion + exit 64 + } + + H - + headers { + lappend ::headersfiles [file normalize [lindex $opt 1]] + } + + M - + markdown { + set ::markdown [lindex $opt 1] + } + + R - + restricted { + set ::scribble 0 + } + } +} + +proc picktmpfilename {filename} { + # blocks until filename does not exist + set ext [clock seconds] + while {[file exists [format "%s.%s" $filename $ext]]} { + incr ext + } + return [format "%s.%s" $filename $ext] +} + +if {[llength $arg] == 2} { + set outputfile [lindex $arg 1]] + if {$ouputfile == "-"} { + } else { + # In the positive, output file desc is already set correctly. + # Alternatively... + if {!$::scribble && [file exists $outputfile]} { + puts stderr [format "Error: output file \'%s\' already exists. You asked me not to scribble on it, so I am not scribbling on it." $outputfile] + exit 73 + } + if {[catch {[open [set ::tmpoutputfile [picktmpfilename [set outputfile [file normalize $outputfile]]]] w]} provoutputfd]} { + puts stderr [format "Error: temporary output file \'%s\' could not be opened for writing. \[open\] reports:" $::tmpoutputfile] + puts stderr $provoutputfd + exit 73 + } { + set ::outputfd $provoutputfd + } + } +} +#continue +if {[llength $arg] > 0} { + set inputfile [lindex $arg 0] + if {$inputfile == "-"} { + } else { + # In the positive, the input file desc is already set correctly. + if {[catch {[open [file normalize $inputfile] r]} provinputfd]} { + puts stderr [format "Error: input file \'%s\' could not be opened for reading. \[open\] reports:" $::inputfile] + puts stderr $provoutputfd + exit 66 + } + } +} +foreach headersfile $::headersfiles