idnits 2.17.1 draft-ietf-netmod-artwork-folding-01.txt: Checking boilerplate required by RFC 5378 and the IETF Trust (see https://trustee.ietf.org/license-info): ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/1id-guidelines.txt: ---------------------------------------------------------------------------- No issues found here. Checking nits according to https://www.ietf.org/id-info/checklist : ---------------------------------------------------------------------------- No issues found here. Miscellaneous warnings: ---------------------------------------------------------------------------- == The copyright year in the IETF Trust and authors Copyright Line does not match the current year -- The document date (March 10, 2019) is 1867 days in the past. Is this intentional? -- Found something which looks like a code comment -- if you have code sections in the document, please surround them with '' and '' lines. Checking references for intended status: Best Current Practice ---------------------------------------------------------------------------- (See RFCs 3967 and 4897 for information about using normative references to lower-maturity documents in RFCs) == Missing Reference: '-r' is mentioned on line 638, but not defined -- Obsolete informational reference (is this intentional?): RFC 7749 (Obsoleted by RFC 7991) Summary: 0 errors (**), 0 flaws (~~), 2 warnings (==), 3 comments (--). Run idnits with the --verbose option for more detailed information about the items above. -------------------------------------------------------------------------------- 2 NETMOD Working Group K. Watsen 3 Internet-Draft Watsen Networks 4 Intended status: Best Current Practice Q. Wu 5 Expires: September 11, 2019 Huawei Technologies 6 A. Farrel 7 Old Dog Consulting 8 B. Claise 9 Cisco Systems, Inc. 10 March 10, 2019 12 Handling Long Lines in Inclusions in Internet-Drafts and RFCs 13 draft-ietf-netmod-artwork-folding-01 15 Abstract 17 This document introduces a simple and yet time-proven strategy for 18 handling long lines in inclusions in drafts using a backslash ('\') 19 character where line-folding has occurred. The strategy works on any 20 text-based content, but is primarily intended for a structured 21 sequence of lines, such as would be referenced by the 22 element defined in Section 2.48 of RFC 7991, rather than for two- 23 dimensional imagery, such as would be referenced by the 24 element defined in Section 2.5 of RFC 7991. The approach produces 25 consistent results, regardless of the content, that is both self- 26 documenting and enables automated reconstitution of the original 27 content. 29 Status of This Memo 31 This Internet-Draft is submitted in full conformance with the 32 provisions of BCP 78 and BCP 79. 34 Internet-Drafts are working documents of the Internet Engineering 35 Task Force (IETF). Note that other groups may also distribute 36 working documents as Internet-Drafts. The list of current Internet- 37 Drafts is at https://datatracker.ietf.org/drafts/current/. 39 Internet-Drafts are draft documents valid for a maximum of six months 40 and may be updated, replaced, or obsoleted by other documents at any 41 time. It is inappropriate to use Internet-Drafts as reference 42 material or to cite them other than as "work in progress." 44 This Internet-Draft will expire on September 11, 2019. 46 Copyright Notice 48 Copyright (c) 2019 IETF Trust and the persons identified as the 49 document authors. All rights reserved. 51 This document is subject to BCP 78 and the IETF Trust's Legal 52 Provisions Relating to IETF Documents 53 (https://trustee.ietf.org/license-info) in effect on the date of 54 publication of this document. Please review these documents 55 carefully, as they describe your rights and restrictions with respect 56 to this document. Code Components extracted from this document must 57 include Simplified BSD License text as described in Section 4.e of 58 the Trust Legal Provisions and are provided without warranty as 59 described in the Simplified BSD License. 61 Table of Contents 63 1. Introduction . . . . . . . . . . . . . . . . . . . . . . . . 3 64 2. Applicability Statement . . . . . . . . . . . . . . . . . . . 3 65 3. Requirements Language . . . . . . . . . . . . . . . . . . . . 4 66 4. Goals . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4 67 4.1. Automated Folding of Long Lines in Text Content . . . . . 4 68 4.2. Automated Reconstitution of the Original Text Content . . 4 69 5. Limitations . . . . . . . . . . . . . . . . . . . . . . . . . 4 70 5.1. Not Recommended for Graphical Artwork . . . . . . . . . . 5 71 5.2. Doesn't Work as Well as Format-Specific Options . . . . . 5 72 6. Folded Structure . . . . . . . . . . . . . . . . . . . . . . 5 73 6.1. Header . . . . . . . . . . . . . . . . . . . . . . . . . 6 74 6.2. Body . . . . . . . . . . . . . . . . . . . . . . . . . . 6 75 7. Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 6 76 7.1. Automated Folding . . . . . . . . . . . . . . . . . . . . 6 77 7.1.1. Manual Folding . . . . . . . . . . . . . . . . . . . 7 78 7.2. Automated Unfolding . . . . . . . . . . . . . . . . . . . 8 79 8. Examples . . . . . . . . . . . . . . . . . . . . . . . . . . 8 80 8.1. Simple Example Showing Boundary Conditions . . . . . . . 9 81 8.2. Example Showing Multiple Wraps of a Single Line . . . . . 9 82 8.3. Example With Native Backslash . . . . . . . . . . . . . . 10 83 8.4. Example With Native Whitespace . . . . . . . . . . . . . 10 84 8.5. Example of Manual Wrapping . . . . . . . . . . . . . . . 10 85 9. Security Considerations . . . . . . . . . . . . . . . . . . . 13 86 10. IANA Considerations . . . . . . . . . . . . . . . . . . . . . 13 87 11. References . . . . . . . . . . . . . . . . . . . . . . . . . 13 88 11.1. Normative References . . . . . . . . . . . . . . . . . . 13 89 11.2. Informative References . . . . . . . . . . . . . . . . . 13 90 Appendix A. POSIX Shell Script . . . . . . . . . . . . . . . . . 15 91 Acknowledgements . . . . . . . . . . . . . . . . . . . . . . . . 19 92 Authors' Addresses . . . . . . . . . . . . . . . . . . . . . . . 20 94 1. Introduction 96 [RFC7994] sets out the requirements for plain-text RFCs and states 97 that each line of an RFC (and hence of an Internet-Draft) must be 98 limited to 72 characters followed by the character sequence that 99 denotes an end-of-line (EOL). 101 Internet-Drafts and RFCs often include example text or code 102 fragments. In order to render the formatting of such text it is 103 usually presented as a figure using the "" element in the 104 source XML. Many times the example text or code exceeds the 72 105 character line-length limit and the `xml2rfc` utility does not 106 attempt to wrap the content of such inclusions, simply issuing a 107 warning whenever lines exceed 69 characters. According to the RFC 108 Editor, there is currently no convention in place for how to handle 109 long lines, other than advising authors to clearly indicate what 110 manipulation has occurred. 112 This document introduces a simple and yet time-proven strategy for 113 handling long lines in inclusions in drafts using a backslash ('\') 114 character where line-folding has occurred. The strategy works on any 115 text based inclusion, but is primarily intended for a structured 116 sequence of lines, such as would be referenced by the 117 element defined in Section 2.48 of [RFC7991], rather than for two- 118 dimensional imagery, such as would be referenced by the 119 element defined in Section 2.5 of [RFC7991]. The approach produces 120 consistent results, regardless of the content, that is both self- 121 documenting and enables automated reconstitution of the original 122 content. 124 Note that text files are represent as lines having their first 125 character in column 1, and a line length of N where the last 126 character is in the Nth column and is immediately followed by an end 127 of line character sequence. 129 2. Applicability Statement 131 The format and algorithm defined in this document may be used in any 132 context, whether for IETF documents or in other situations where 133 structured folding is desired. 135 Within the IETF, this work is primarily targeted to xml2rfc v3 136 element (Section 2.48 of [RFC7991]) and xml2rfc v2 137 element (Section 2.5 of [RFC7749]) that, for lack of a 138 better option, is currently used for both source code and artwork. 139 This work may be also be used for the xml2rfc v3 element 140 (Section 2.5 of [RFC7991]) but, as described in Section 5.1, it is 141 generally not recommended. 143 3. Requirements Language 145 The key words "MUST", "MUST NOT", "REQUIRED", "SHALL", "SHALL NOT", 146 "SHOULD", "SHOULD NOT", "RECOMMENDED", "NOT RECOMMENDED", "MAY", and 147 "OPTIONAL" in this document are to be interpreted as described in BCP 148 14 [RFC2119] [RFC8174] when, and only when, they appear in all 149 capitals, as shown here. 151 4. Goals 153 4.1. Automated Folding of Long Lines in Text Content 155 Automated folding of long lines is needed in order to support draft 156 compilations that entail a) validation of source input files (e.g., 157 XML, JSON, ABNF, ASN.1) and/or b) dynamic generation of output, using 158 a tool that doesn't observe line lengths, that is stitched into the 159 final document to be submitted. 161 Generally, in order for tooling to be able to process input files, 162 the files must be in their original/natural state, which may include 163 having some long lines. Thus, these source files need to be modified 164 before inclusion in the document in order to satisfy the line length 165 limits. This modification SHOULD be automated to reduce effort and 166 errors resulting from manual effort. 168 Similarly, dynamically generated output (e.g., tree diagrams) must 169 also be modified, if necessary, in order for the resulting document 170 to satisfy the line length limits. When needed, this effort again 171 SHOULD be automated to reduce effort and errors resulting from manual 172 effort. 174 4.2. Automated Reconstitution of the Original Text Content 176 Automated reconstitution of the original content is needed to support 177 validation of artwork extracted from documents. YANG [RFC7950] 178 modules are already extracted from Internet-Drafts and validated as 179 part of the draft-submission process. Additionally, there has been 180 some discussion regarding needing to do the same for instance 181 examples (i.e., XML/JSON documents) contained within Internet-Drafts 182 ([yang-doctors-thread]). Thus, it SHOULD be possible to mechanically 183 reconstitute the original text content in order to satisfy tooling 184 input parsers. 186 5. Limitations 187 5.1. Not Recommended for Graphical Artwork 189 While the solution presented in this document will work on any kind 190 of text-based content, it is most useful on content that represents 191 source code (XML, JSON, etc.) or, more generally, on content that has 192 not been laid out in two dimensions (e.g., diagrams). 194 Fundamentally, the issue is whether the text content remains readable 195 once folded. Text content that is unpredictable is especially 196 susceptible to looking bad when folded; falling into this category 197 are most UML diagrams, YANG tree diagrams, and ASCII art in general. 199 It is NOT RECOMMENDED to use the solution presented in this document 200 on graphical artwork. 202 5.2. Doesn't Work as Well as Format-Specific Options 204 The solution presented in this document works generically for all 205 text-based content, as it only views content as plain text. However, 206 various formats sometimes have built-in mechanisms that are better 207 suited to prevent long lines. 209 For instance, both the `pyang` and `yanglint` utilities have the 210 command line option "--tree-line-length" that can be used to indicate 211 a desired maximum line length for when generating tree diagrams 212 [RFC8340]. 214 In another example, some source formats (e.g., YANG [RFC7950]) allow 215 any quoted string to be broken up into substrings separated by a 216 concatenation character (e.g., '+'), any of which can be on a 217 different line. 219 In yet another example, some languages allow factoring blocks of code 220 into call outs, such as functions. Using such call outs is 221 especially helpful when in some deeply-nested code, as they typically 222 reset the indentation back to the first column. 224 It is RECOMMENDED that authors do as much as possible within the 225 selected format to avoid long lines. 227 6. Folded Structure 229 Text content that has been folded as specified by this document MUST 230 contain the following structure. 232 6.1. Header 234 The header is two lines long. 236 The first line is the following 46-character string that MAY be 237 surrounded by any number of printable characters. This first line 238 cannot itself be folded. 240 NOTE: '\\' line wrapping per BCP XX (RFC XXXX) 242 [Note to RFC Editor: Please replace XX and XXXX with the numbers 243 assigned to this document and delete this note. Please make this 244 change in multiple places in this document.] 246 The second line is a blank line. This line provides visual 247 separation for readability. 249 6.2. Body 251 The character encoding is the same as described in Section 2 of 252 [RFC7994], except that, per [RFC7991], tab characters are prohibited. 254 Lines that have a backslash ('\') occurring as the last character in 255 a line immediately followed by the end of line character sequence, 256 when the subsequent line starts with a backslash ('\') as the first 257 non-space (' ') character, are considered "folded". 259 Really long lines may be folded multiple times. 261 7. Algorithm 263 This section describes the processes for folding and unfolding long 264 lines when they are encountered in a single instance of text content. 265 It is assumed that another process inserts/extracts the individual 266 text content instances to/from an Internet-Draft or RFC. For 267 example, the `xiax` utility [xiax] does just this. 269 7.1. Automated Folding 271 Determine the desired maximum line length from input to the automated 272 line-wrapping process, such as from a command line parameter. If no 273 value is explicitly specified, the value "69" SHOULD be used. 275 Ensure that the desired maximum line length is not less than the 276 minimum header, which is 46 characters. If the desired maximum line 277 length is less than this minimum, exit (this text-based content 278 cannot be folded). 280 Scan the text content for horizontal tab characters. If any 281 horizontal tab characters appear, either resolve them to space 282 characters or exit, forcing the input provider to convert them to 283 space characters themselves first. 285 Scan the text content to see if any line exceeds the desired maximum. 286 If no line exceeds the desired maximum, exit (this text content does 287 not need to be folded). 289 Scan the text content to ensure no existing lines already end with a 290 backslash ('\') character when the subsequent line starts with a 291 backslash ('\') character as the first non-space (' ') character, as 292 this would lead to an ambiguous result. If such a line is found, 293 exit (this text content cannot be folded). 295 If this text content needs to and can be folded, insert the header as 296 described in Section 6.1. 298 For each line in the text content, from top-to-bottom, if the line 299 exceeds the desired maximum, then fold the line at the desired 300 maximum column by 1) inserting the character backslash ('\') 301 character at the maximum column, 2) inserting the end of line 302 character sequence, inserting any number of space (' ') characters, 303 and 4) inserting a further backslash ('\') character. 305 The result of this previous operation is that the next line starts 306 with an arbitrary number of space (' ') characters, followed by a 307 backslash ('\') character, immediately followed by the character that 308 was previously in the maximum column. 310 Continue in this manner until reaching the end of the text content. 311 Note that this algorithm naturally addresses the case where the 312 remainder of a folded line is still longer than the desired maximum, 313 and hence needs to be folded again, ad infinitum. 315 The process described in this section is illustrated by the 316 "fold_it()" function in Appendix A. 318 7.1.1. Manual Folding 320 Authors may choose to fold text examples and source code by hand to 321 produce a text content that is more pleasant for a human reader but 322 which can still be automatically unfolded (as described in 323 Section 7.2) to produce single lines that are longer than the maximum 324 document line length. 326 For example, an author may choose to make the fold at convenient gaps 327 between words such that the backslash is placed in a lower column 328 number than the text content's maximum column value. 330 Additionally, an author may choose to indent the start of a 331 continuation line by inserting space characters before the line 332 continuation marker backslash character. 334 Manual folding may also help handle the cases that cannot be 335 automatically folded as described in Section 7. 337 Authors MUST produce a result that adheres to the structure described 338 in Section 6. 340 7.2. Automated Unfolding 342 All unfolding is assumed to be automated although a reader will 343 mentally perform the act of unfolding the text to understand the true 344 nature of the original text content. 346 Scan the beginning of the text content for the header described in 347 Section 6.1. If the header is not present, starting on the first 348 line of the text content, exit (this artwork does not need to be 349 unfolded). 351 Remove the 2-line header from the text content. 353 For each line in the text content, from top-to-bottom, if the line 354 has a backslash ('\') character immediately followed by the end of 355 line character sequence, and if the next line has a backslash ('\') 356 character as the first non-space (' ') character, then the lines can 357 be unfolded. Remove the first backslash ('\') character, the end of 358 line character sequence, any leading space (' ') characters, and the 359 second backslash ('\') character, which will bring up the next line. 360 Then continue to scan each line in the text content starting with the 361 current line (in case it was multiply folded). 363 Continue in this manner until reaching the end of the text content. 365 The process described in this section is illustrated by the 366 "unfold_it()" function in Appendix A. 368 8. Examples 370 The following self-documenting examples illustrate folded text-based 371 content. 373 The source text content cannot be presented here, as it would again 374 need to be folded. Alas, only the result can be provided. 376 The examples in Sections 8.1 through 8.4 were automatically folded on 377 column 69, the default value. Section 8.5 shows an example of manual 378 folding. 380 8.1. Simple Example Showing Boundary Conditions 382 This example illustrates a boundary condition test using numbers for 383 counting purposes. The input contains 5 lines, each line one 384 character longer than the previous. 386 Any printable character (including ' ' and '\') can be used as a 387 substitute for any number, except for on the 4th row, the trailing 388 '9' is not allowed to be a '\' character if the first non-space 389 character of the next line is a '\' character, as that would lead to 390 an ambiguous result. 392 ========== NOTE: '\\' line wrapping per BCP XX (RFC XXXX) =========== 394 123456789012345678901234567890123456789012345678901234567890123456 395 1234567890123456789012345678901234567890123456789012345678901234567 396 12345678901234567890123456789012345678901234567890123456789012345678 397 123456789012345678901234567890123456789012345678901234567890123456789 398 12345678901234567890123456789012345678901234567890123456789012345678\ 399 \90 400 12345678901234567890123456789012345678901234567890123456789012345678\ 401 \901 402 12345678901234567890123456789012345678901234567890123456789012345678\ 403 \9012 405 8.2. Example Showing Multiple Wraps of a Single Line 407 This example illustrates one very long line (280 characters). 409 Any printable character (including ' ' and '\') can be used as a 410 substitute for any number. 412 ========== NOTE: '\\' line wrapping per BCP XX (RFC XXXX) =========== 414 12345678901234567890123456789012345678901234567890123456789012345678\ 415 \9012345678901234567890123456789012345678901234567890123456789012345\ 416 \6789012345678901234567890123456789012345678901234567890123456789012\ 417 \3456789012345678901234567890123456789012345678901234567890123456789\ 418 \01234567890 420 8.3. Example With Native Backslash 422 This example has a '\' character in the wrapping column. The native 423 text includes the sequence "fish\fowl" with the '\' character 424 occurring on the 69th column. 426 string1="The quick brown dog jumps over the lazy dog which is a fish\ 427 \\fowl as appropriate" 429 8.4. Example With Native Whitespace 431 This example has whitespace spanning the wrapping column. The native 432 input contains 15 space (' ') characters between "like" and "white". 434 ========== NOTE: '\\' line wrapping per BCP XX (RFC XXXX) =========== 436 Sometimes our strings include multiple spaces such as "We like \ 437 \ white space." 439 8.5. Example of Manual Wrapping 441 This example was manually wrapped to cause the folding to occur after 442 each term, putting each term on its own line. Indentation is used to 443 additionally improve readability. Also note that the mandatory 444 header is surrounded by different printable characters than shown in 445 the other examples. 447 ===== NOTE: '\\' line wrapping per BCP XX (RFC XXXX) ===== 449 453 454 config-modules 455 456 ietf-interfaces 457 2018-02-20 458 \ 459 \urn:ietf:params:xml:ns:yang:ietf-interfaces\ 460 \ 461 462 463 ietf-ip 464 2018-02-22 465 \ 466 \urn:ietf:params:xml:ns:yang:ietf-ip\ 468 \ 469 470 471 ietf-yang-types 472 2013-07-15 473 \ 474 \urn:ietf:params:xml:ns:yang:ietf-yang-types\ 475 \ 476 477 478 ietf-inet-types 479 2013-07-15 480 \ 481 \urn:ietf:params:xml:ns:yang:ietf-inet-types\ 482 \ 483 484 486 487 config-schema 488 config-modules 489 490 491 state-schema 492 config-modules 493 state-modules 494 496 497 ds:startup 498 config-schema 499 500 501 ds:running 502 config-schema 503 504 505 ds:operational 506 state-schema 507 509 75a43df9bd56b92aacc156a2958fbe12312fb285 510 512 The manual folding produces a more readable result than the following 513 equivalent folding that contains no indentation. 515 ========== NOTE: '\\' line wrapping per BCP XX (RFC XXXX) =========== 516 520 521 config-modules 522 523 ietf-interfaces 524 2018-02-20 525 urn:ietf:params:xml:ns:yang:ietf-interfaces 527 528 529 ietf-ip 530 2018-02-22 531 urn:ietf:params:xml:ns:yang:ietf-ip 532 533 534 ietf-yang-types 535 2013-07-15 536 urn:ietf:params:xml:ns:yang:ietf-yang-types 538 539 540 ietf-inet-types 541 2013-07-15 542 urn:ietf:params:xml:ns:yang:ietf-inet-types 544 545 547 548 config-schema 549 config-modules 550 551 552 state-schema 553 config-modules 554 state-modules 555 557 558 ds:startup 559 config-schema 560 561 562 ds:running 563 config-schema 565 566 567 ds:operational 568 state-schema 569 571 75a43df9bd56b92aacc156a2958fbe12312fb285 572 574 9. Security Considerations 576 This BCP has no Security Considerations. 578 10. IANA Considerations 580 This BCP has no IANA Considerations. 582 11. References 584 11.1. Normative References 586 [RFC2119] Bradner, S., "Key words for use in RFCs to Indicate 587 Requirement Levels", BCP 14, RFC 2119, 588 DOI 10.17487/RFC2119, March 1997, 589 . 591 [RFC8174] Leiba, B., "Ambiguity of Uppercase vs Lowercase in RFC 592 2119 Key Words", BCP 14, RFC 8174, DOI 10.17487/RFC8174, 593 May 2017, . 595 11.2. Informative References 597 [RFC7749] Reschke, J., "The "xml2rfc" Version 2 Vocabulary", 598 RFC 7749, DOI 10.17487/RFC7749, February 2016, 599 . 601 [RFC7950] Bjorklund, M., Ed., "The YANG 1.1 Data Modeling Language", 602 RFC 7950, DOI 10.17487/RFC7950, August 2016, 603 . 605 [RFC7991] Hoffman, P., "The "xml2rfc" Version 3 Vocabulary", 606 RFC 7991, DOI 10.17487/RFC7991, December 2016, 607 . 609 [RFC7994] Flanagan, H., "Requirements for Plain-Text RFCs", 610 RFC 7994, DOI 10.17487/RFC7994, December 2016, 611 . 613 [RFC8340] Bjorklund, M. and L. Berger, Ed., "YANG Tree Diagrams", 614 BCP 215, RFC 8340, DOI 10.17487/RFC8340, March 2018, 615 . 617 [xiax] "The `xiax` Python Package", 618 . 620 [yang-doctors-thread] 621 "[yang-doctors] automating yang doctor reviews", 622 . 625 Appendix A. POSIX Shell Script 627 This non-normative appendix section includes a shell script that can 628 both fold and unfold text content. Note that this script is applied 629 only to single text content instances. 631 #!/bin/bash 633 print_usage() { 634 echo 635 echo "Folds the text file, only if needed, at the specified" 636 echo "column, according to BCP XX." 637 echo 638 echo "Usage: $0 [-c ] [-r] -i -o " 639 echo 640 echo " -c: column to fold on (default: 69)" 641 echo " -r: reverses the operation" 642 echo " -i: the input filename" 643 echo " -o: the output filename" 644 echo " -d: show debug messages" 645 echo " -h: show this message" 646 echo 647 echo "Exit status code: zero on success, non-zero otherwise." 648 echo 649 } 651 # global vars, do not edit 652 debug=0 653 reversed=0 654 infile="" 655 outfile="" 656 maxcol=69 # default, may be overridden by param 657 hdr_txt="NOTE: '\\\\' line wrapping per BCP XX (RFC XXXX)" 658 equal_chars="==============================================" 659 space_chars=" " 661 fold_it() { 662 # since upcomming tests are >= (not >) 663 testcol=`expr "$maxcol" + 1` 665 # check if file needs folding 666 grep ".\{$testcol\}" $infile >> /dev/null 2>&1 667 if [ $? -ne 0 ]; then 668 if [[ $debug -eq 1 ]]; then 669 echo "nothing to do" 670 fi 671 cp $infile $outfile 672 return -1 673 fi 675 foldcol=`expr "$maxcol" - 1` # for the inserted '\' char 677 # ensure input file doesn't contain a TAB 678 grep $'\t' $infile >> /dev/null 2>&1 679 if [ $? -eq 0 ]; then 680 echo 681 echo "Error: infile contains a TAB character, which is not" 682 echo "allowed." 683 echo 684 return 1 685 fi 687 # ensure input file doesn't contain the fold-sequence already 688 pcregrep -M "\\\\\n[\ ]*\\\\" $infile >> /dev/null 2>&1 689 if [ $? -eq 0 ]; then 690 echo 691 echo "Error: infile has a line ending with a '\' character" 692 echo " followed by a '\' character as the first non-space" 693 echo " character on the next line. This file cannot be" 694 echo " folded." 695 echo 696 return 1 697 fi 699 # center header text 700 length=`expr ${#hdr_txt} + 2` 701 left_sp=`expr \( "$maxcol" - "$length" \) / 2` 702 right_sp=`expr "$maxcol" - "$length" - "$left_sp"` 703 header=`printf "%.*s %s %.*s" "$left_sp" "$equal_chars"\ 704 "$hdr_txt" "$right_sp" "$equal_chars"` 706 # fold using recursive passes ('g' didn't work) 707 if [ -z "$1" ]; then 708 # init recursive env 709 cp $infile /tmp/wip 710 fi 711 gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n\\\\/" < /tmp/wip\ 712 >> /tmp/wip2 713 diff /tmp/wip /tmp/wip2 > /dev/null 2>&1 714 if [ $? -eq 1 ]; then 715 mv /tmp/wip2 /tmp/wip 716 fold_it "recursing" 717 else 718 echo "$header" > $outfile 719 echo "" >> $outfile 720 cat /tmp/wip2 >> $outfile 721 rm /tmp/wip* 722 fi 724 ## following two lines represent a non-functional variant to the 725 ## recursive logic presented in the block above. It used to work 726 ## before the '\' on the next line was added to the format (i.e., 727 ## the trailing '\\\\' in the substitution below), but now there 728 ## is an off-by-one error. Leaving here in case anyone can fix it. 729 #echo "$header" > $outfile 730 #echo "" >> $outfile 731 #gsed "/.\{$testcol\}/s/\(.\{$foldcol\}\)/\1\\\\\n\\\\/g"\ 732 < $infile >> $outfile 734 return 0 735 } 737 unfold_it() { 738 # check if file needs unfolding 739 line=`head -n 1 $infile | fgrep "$hdr_txt"` 740 if [ $? -ne 0 ]; then 741 if [[ $debug -eq 1 ]]; then 742 echo "nothing to do" 743 fi 744 cp $infile $outfile 745 return -1 746 fi 748 # output all but the first two lines (the header) to wip (work 749 # in progress) file 750 awk "NR>2" $infile > /tmp/wip 752 # unfold wip file 753 gsed ":x; /.*\\\\\$/N; s/\\\\\n[ ]*\\\\//; tx; s/\t//g" /tmp/wip\ 754 > $outfile 756 # clean up and return 757 rm /tmp/wip 758 return 0 759 } 761 process_input() { 762 while [ "$1" != "" ]; do 763 if [ "$1" == "-h" -o "$1" == "--help" ]; then 764 print_usage 765 exit 1 767 fi 768 if [ "$1" == "-d" ]; then 769 debug=1 770 fi 771 if [ "$1" == "-c" ]; then 772 maxcol="$2" 773 shift 774 fi 775 if [ "$1" == "-r" ]; then 776 reversed=1 777 fi 778 if [ "$1" == "-i" ]; then 779 infile="$2" 780 shift 781 fi 782 if [ "$1" == "-o" ]; then 783 outfile="$2" 784 shift 785 fi 786 shift 787 done 789 if [ -z "$infile" ]; then 790 echo 791 echo "Error: infile parameter missing (use -h for help)" 792 echo 793 exit 1 794 fi 796 if [ -z "$outfile" ]; then 797 echo 798 echo "Error: outfile parameter missing (use -h for help)" 799 echo 800 exit 1 801 fi 803 if [ ! -f "$infile" ]; then 804 echo 805 echo "Error: specified file \"$infile\" is does not exist." 806 echo 807 exit 1 808 fi 810 min_supported=`expr ${#hdr_txt} + 8` 811 if [ $maxcol -lt $min_supported ]; then 812 echo 813 echo "Error: the folding column cannot be less than" 814 echo "$min_supported" 815 echo 816 exit 1 817 fi 819 max_supported=`expr ${#equal_chars} + 1 + ${#hdr_txt} + 1\ 820 + ${#equal_chars}` 821 if [ $maxcol -gt $max_supported ]; then 822 echo 823 echo "Error: the folding column cannot be more than" 824 echo "$max_supported" 825 echo 826 exit 1 827 fi 829 } 831 main() { 832 if [ "$#" == "0" ]; then 833 print_usage 834 exit 1 835 fi 837 process_input $@ 839 if [[ $reversed -eq 0 ]]; then 840 fold_it 841 code=$? 842 else 843 unfold_it 844 code=$? 845 fi 846 exit $code 847 } 849 main "$@" 851 Acknowledgements 853 The authors thank the following folks for their various contributions 854 (sorted by first name): Gianmarco Bruno, Italo Busi, Jonathan 855 Hansford, Joel Jaeggli, Lou Berger, Martin Bjorklund, Italo Busi, and 856 Rob Wilton. 858 The authors additionally thank the RFC Editor for confirming that 859 there is no set convention today for handling long lines in artwork/ 860 sourcecode inclusions. 862 Authors' Addresses 864 Kent Watsen 865 Watsen Networks 867 EMail: kent+ietf@watsen.net 869 Qin Wu 870 Huawei Technologies 872 EMail: bill.wu@huawei.com 874 Adrian Farrel 875 Old Dog Consulting 877 EMail: adrian@olddog.co.uk 879 Benoit Claise 880 Cisco Systems, Inc. 882 EMail: bclaise@cisco.com