diff options
-rw-r--r-- | doc/ChangeLog | 6 | ||||
-rw-r--r-- | doc/gawk.info | 1032 | ||||
-rw-r--r-- | doc/gawk.texi | 68 | ||||
-rw-r--r-- | doc/gawktexi.in | 68 |
4 files changed, 598 insertions, 576 deletions
diff --git a/doc/ChangeLog b/doc/ChangeLog index 9fc9aafa..591cbd64 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,9 @@ +2019-06-18 Arnold D. Robbins <arnold@skeeve.com> + + * gawktexi.in (Plain Getline): Improve the program and show + sample input and output. Thanks to Mark Krauze <daburashka@ya.ru> + for some of the changes. + 2019-06-11 Arnold D. Robbins <arnold@skeeve.com> * gawktexi.in (Regexp Operator Details): Add a paragraph diff --git a/doc/gawk.info b/doc/gawk.info index cf0cab9d..1e8bf194 100644 --- a/doc/gawk.info +++ b/doc/gawk.info @@ -5759,28 +5759,19 @@ the next record _right now_. For example: # Remove text between /* and */, inclusive { - if ((i = index($0, "/*")) != 0) { - out = substr($0, 1, i - 1) # leading part of the string - rest = substr($0, i + 2) # ... */ ... - j = index(rest, "*/") # is */ in trailing part? - if (j > 0) { - rest = substr(rest, j + 2) # remove comment - } else { - while (j == 0) { - # get more text - if (getline <= 0) { - print("unexpected EOF or error:", ERRNO) > "/dev/stderr" - exit - } - # build up the line using string concatenation - rest = rest $0 - j = index(rest, "*/") # is */ in trailing part? - if (j != 0) { - rest = substr(rest, j + 2) - break - } + while ((start = index($0, "/*")) != 0) { + out = substr($0, 1, start - 1) # leading part of the string + rest = substr($0, start + 2) # ... */ ... + while ((end = index(rest, "*/")) == 0) { # is */ in trailing part? + # get more text + if (getline <= 0) { + print("unexpected EOF or error:", ERRNO) > "/dev/stderr" + exit } + # build up the line using string concatenation + rest = rest $0 } + rest = substr(rest, end + 2) # remove comment # build up the output line using string concatenation $0 = out rest } @@ -5793,8 +5784,25 @@ string concatenation (*note Concatenation::) and the 'index()' and 'substr()' built-in functions (*note String Functions::). By replacing the 'print $0' with other statements, you could perform more complicated processing on the decommented input, such as searching for matches of a -regular expression. (This program has a subtle problem--it does not -work if one comment ends and another begins on the same line.) +regular expression. + + Here is some sample input: + + mon/*comment*/key + rab/*commen + t*/bit + horse /*comment*/more text + part 1 /*comment*/part 2 /*comment*/part 3 + no comment + + When run, the output is: + + $ awk -f strip_comments.awk example_text + -| monkey + -| rabbit + -| horse more text + -| part 1 part 2 part 3 + -| no comment This form of the 'getline' command sets 'NF', 'NR', 'FNR', 'RT', and the value of '$0'. @@ -37010,495 +37018,495 @@ Node: Testing field creation247759 Node: Multiple Line249384 Node: Getline255661 Node: Plain Getline258130 -Node: Getline/Variable260771 -Node: Getline/File261922 -Node: Getline/Variable/File263310 -Ref: Getline/Variable/File-Footnote-1264915 -Node: Getline/Pipe265003 -Node: Getline/Variable/Pipe267710 -Node: Getline/Coprocess268845 -Node: Getline/Variable/Coprocess270112 -Node: Getline Notes270854 -Node: Getline Summary273651 -Ref: table-getline-variants274075 -Node: Read Timeout274823 -Ref: Read Timeout-Footnote-1278729 -Node: Retrying Input278787 -Node: Command-line directories279986 -Node: Input Summary280892 -Node: Input Exercises284064 -Node: Printing284792 -Node: Print286626 -Node: Print Examples288083 -Node: Output Separators290863 -Node: OFMT292880 -Node: Printf294236 -Node: Basic Printf295021 -Node: Control Letters296595 -Node: Format Modifiers301759 -Node: Printf Examples307774 -Node: Redirection310260 -Node: Special FD317101 -Ref: Special FD-Footnote-1320269 -Node: Special Files320343 -Node: Other Inherited Files320960 -Node: Special Network321961 -Node: Special Caveats322821 -Node: Close Files And Pipes323770 -Ref: table-close-pipe-return-values330677 -Ref: Close Files And Pipes-Footnote-1331490 -Ref: Close Files And Pipes-Footnote-2331638 -Node: Nonfatal331790 -Node: Output Summary334128 -Node: Output Exercises335350 -Node: Expressions336029 -Node: Values337217 -Node: Constants337895 -Node: Scalar Constants338586 -Ref: Scalar Constants-Footnote-1341110 -Node: Nondecimal-numbers341360 -Node: Regexp Constants344361 -Node: Using Constant Regexps344887 -Node: Standard Regexp Constants345509 -Node: Strong Regexp Constants348697 -Node: Variables351655 -Node: Using Variables352312 -Node: Assignment Options354222 -Node: Conversion356689 -Node: Strings And Numbers357213 -Ref: Strings And Numbers-Footnote-1360276 -Node: Locale influences conversions360385 -Ref: table-locale-affects363143 -Node: All Operators363761 -Node: Arithmetic Ops364390 -Node: Concatenation366896 -Ref: Concatenation-Footnote-1369743 -Node: Assignment Ops369850 -Ref: table-assign-ops374841 -Node: Increment Ops376154 -Node: Truth Values and Conditions379614 -Node: Truth Values380688 -Node: Typing and Comparison381736 -Node: Variable Typing382556 -Ref: Variable Typing-Footnote-1389019 -Ref: Variable Typing-Footnote-2389091 -Node: Comparison Operators389168 -Ref: table-relational-ops389587 -Node: POSIX String Comparison393082 -Ref: POSIX String Comparison-Footnote-1394777 -Ref: POSIX String Comparison-Footnote-2394916 -Node: Boolean Ops395000 -Ref: Boolean Ops-Footnote-1399482 -Node: Conditional Exp399574 -Node: Function Calls401310 -Node: Precedence405187 -Node: Locales408846 -Node: Expressions Summary410478 -Node: Patterns and Actions413051 -Node: Pattern Overview414171 -Node: Regexp Patterns415848 -Node: Expression Patterns416390 -Node: Ranges420171 -Node: BEGIN/END423279 -Node: Using BEGIN/END424040 -Ref: Using BEGIN/END-Footnote-1426776 -Node: I/O And BEGIN/END426882 -Node: BEGINFILE/ENDFILE429196 -Node: Empty432109 -Node: Using Shell Variables432426 -Node: Action Overview434700 -Node: Statements437025 -Node: If Statement438873 -Node: While Statement440368 -Node: Do Statement442396 -Node: For Statement443544 -Node: Switch Statement446715 -Node: Break Statement449101 -Node: Continue Statement451193 -Node: Next Statement453020 -Node: Nextfile Statement455403 -Node: Exit Statement458055 -Node: Built-in Variables460458 -Node: User-modified461591 -Node: Auto-set469358 -Ref: Auto-set-Footnote-1486165 -Ref: Auto-set-Footnote-2486371 -Node: ARGC and ARGV486427 -Node: Pattern Action Summary490640 -Node: Arrays493070 -Node: Array Basics494399 -Node: Array Intro495243 -Ref: figure-array-elements497218 -Ref: Array Intro-Footnote-1499922 -Node: Reference to Elements500050 -Node: Assigning Elements502514 -Node: Array Example503005 -Node: Scanning an Array504764 -Node: Controlling Scanning507786 -Ref: Controlling Scanning-Footnote-1513185 -Node: Numeric Array Subscripts513501 -Node: Uninitialized Subscripts515685 -Node: Delete517304 -Ref: Delete-Footnote-1520056 -Node: Multidimensional520113 -Node: Multiscanning523208 -Node: Arrays of Arrays524799 -Node: Arrays Summary529567 -Node: Functions531660 -Node: Built-in532698 -Node: Calling Built-in533779 -Node: Numeric Functions535775 -Ref: Numeric Functions-Footnote-1539803 -Ref: Numeric Functions-Footnote-2540451 -Ref: Numeric Functions-Footnote-3540499 -Node: String Functions540771 -Ref: String Functions-Footnote-1564629 -Ref: String Functions-Footnote-2564757 -Ref: String Functions-Footnote-3565005 -Node: Gory Details565092 -Ref: table-sub-escapes566883 -Ref: table-sub-proposed568402 -Ref: table-posix-sub569765 -Ref: table-gensub-escapes571306 -Ref: Gory Details-Footnote-1572129 -Node: I/O Functions572283 -Ref: table-system-return-values578751 -Ref: I/O Functions-Footnote-1580831 -Ref: I/O Functions-Footnote-2580979 -Node: Time Functions581099 -Ref: Time Functions-Footnote-1591770 -Ref: Time Functions-Footnote-2591838 -Ref: Time Functions-Footnote-3591996 -Ref: Time Functions-Footnote-4592107 -Ref: Time Functions-Footnote-5592219 -Ref: Time Functions-Footnote-6592446 -Node: Bitwise Functions592712 -Ref: table-bitwise-ops593306 -Ref: Bitwise Functions-Footnote-1599369 -Ref: Bitwise Functions-Footnote-2599542 -Node: Type Functions599733 -Node: I18N Functions602596 -Node: User-defined604247 -Node: Definition Syntax605059 -Ref: Definition Syntax-Footnote-1610746 -Node: Function Example610817 -Ref: Function Example-Footnote-1613739 -Node: Function Calling613761 -Node: Calling A Function614349 -Node: Variable Scope615307 -Node: Pass By Value/Reference618301 -Node: Function Caveats620945 -Ref: Function Caveats-Footnote-1622992 -Node: Return Statement623112 -Node: Dynamic Typing626091 -Node: Indirect Calls627021 -Ref: Indirect Calls-Footnote-1637273 -Node: Functions Summary637401 -Node: Library Functions640106 -Ref: Library Functions-Footnote-1643713 -Ref: Library Functions-Footnote-2643856 -Node: Library Names644027 -Ref: Library Names-Footnote-1647694 -Ref: Library Names-Footnote-2647917 -Node: General Functions648003 -Node: Strtonum Function649106 -Node: Assert Function652128 -Node: Round Function655454 -Node: Cliff Random Function656994 -Node: Ordinal Functions658010 -Ref: Ordinal Functions-Footnote-1661073 -Ref: Ordinal Functions-Footnote-2661325 -Node: Join Function661535 -Ref: Join Function-Footnote-1663305 -Node: Getlocaltime Function663505 -Node: Readfile Function667247 -Node: Shell Quoting669224 -Node: Data File Management670625 -Node: Filetrans Function671257 -Node: Rewind Function675353 -Node: File Checking677262 -Ref: File Checking-Footnote-1678596 -Node: Empty Files678797 -Node: Ignoring Assigns680776 -Node: Getopt Function682326 -Ref: Getopt Function-Footnote-1693795 -Node: Passwd Functions693995 -Ref: Passwd Functions-Footnote-1702834 -Node: Group Functions702922 -Ref: Group Functions-Footnote-1710820 -Node: Walking Arrays711027 -Node: Library Functions Summary714035 -Node: Library Exercises715441 -Node: Sample Programs715906 -Node: Running Examples716676 -Node: Clones717404 -Node: Cut Program718628 -Node: Egrep Program728557 -Ref: Egrep Program-Footnote-1736069 -Node: Id Program736179 -Node: Split Program739859 -Ref: Split Program-Footnote-1743317 -Node: Tee Program743446 -Node: Uniq Program746236 -Node: Wc Program753857 -Ref: Wc Program-Footnote-1758112 -Node: Miscellaneous Programs758206 -Node: Dupword Program759419 -Node: Alarm Program761449 -Node: Translate Program766304 -Ref: Translate Program-Footnote-1770869 -Node: Labels Program771139 -Ref: Labels Program-Footnote-1774490 -Node: Word Sorting774574 -Node: History Sorting778646 -Node: Extract Program780481 -Node: Simple Sed788535 -Node: Igawk Program791609 -Ref: Igawk Program-Footnote-1805940 -Ref: Igawk Program-Footnote-2806142 -Ref: Igawk Program-Footnote-3806264 -Node: Anagram Program806379 -Node: Signature Program809441 -Node: Programs Summary810688 -Node: Programs Exercises811902 -Ref: Programs Exercises-Footnote-1816031 -Node: Advanced Features816122 -Node: Nondecimal Data818112 -Node: Array Sorting819703 -Node: Controlling Array Traversal820403 -Ref: Controlling Array Traversal-Footnote-1828771 -Node: Array Sorting Functions828889 -Ref: Array Sorting Functions-Footnote-1833980 -Node: Two-way I/O834176 -Ref: Two-way I/O-Footnote-1841897 -Ref: Two-way I/O-Footnote-2842084 -Node: TCP/IP Networking842166 -Node: Profiling845284 -Node: Advanced Features Summary854299 -Node: Internationalization856143 -Node: I18N and L10N857623 -Node: Explaining gettext858310 -Ref: Explaining gettext-Footnote-1864202 -Ref: Explaining gettext-Footnote-2864387 -Node: Programmer i18n864552 -Ref: Programmer i18n-Footnote-1869501 -Node: Translator i18n869550 -Node: String Extraction870344 -Ref: String Extraction-Footnote-1871476 -Node: Printf Ordering871562 -Ref: Printf Ordering-Footnote-1874348 -Node: I18N Portability874412 -Ref: I18N Portability-Footnote-1876868 -Node: I18N Example876931 -Ref: I18N Example-Footnote-1880206 -Ref: I18N Example-Footnote-2880279 -Node: Gawk I18N880388 -Node: I18N Summary881037 -Node: Debugger882378 -Node: Debugging883378 -Node: Debugging Concepts883819 -Node: Debugging Terms885628 -Node: Awk Debugging888203 -Ref: Awk Debugging-Footnote-1889148 -Node: Sample Debugging Session889280 -Node: Debugger Invocation889814 -Node: Finding The Bug891200 -Node: List of Debugger Commands897674 -Node: Breakpoint Control899007 -Node: Debugger Execution Control902701 -Node: Viewing And Changing Data906063 -Node: Execution Stack909604 -Node: Debugger Info911241 -Node: Miscellaneous Debugger Commands915312 -Node: Readline Support920374 -Node: Limitations921270 -Node: Debugging Summary923824 -Node: Namespaces925103 -Node: Global Namespace926182 -Node: Qualified Names927580 -Node: Default Namespace928579 -Node: Changing The Namespace929320 -Node: Naming Rules930934 -Node: Internal Name Management932782 -Node: Namespace Example933824 -Node: Namespace And Features936386 -Node: Namespace Summary937821 -Node: Arbitrary Precision Arithmetic939298 -Node: Computer Arithmetic940785 -Ref: table-numeric-ranges944551 -Ref: table-floating-point-ranges945044 -Ref: Computer Arithmetic-Footnote-1945702 -Node: Math Definitions945759 -Ref: table-ieee-formats949075 -Ref: Math Definitions-Footnote-1949678 -Node: MPFR features949783 -Node: FP Math Caution951501 -Ref: FP Math Caution-Footnote-1952573 -Node: Inexactness of computations952942 -Node: Inexact representation953902 -Node: Comparing FP Values955262 -Node: Errors accumulate956503 -Node: Getting Accuracy957936 -Node: Try To Round960646 -Node: Setting precision961545 -Ref: table-predefined-precision-strings962242 -Node: Setting the rounding mode964072 -Ref: table-gawk-rounding-modes964446 -Ref: Setting the rounding mode-Footnote-1968377 -Node: Arbitrary Precision Integers968556 -Ref: Arbitrary Precision Integers-Footnote-1971731 -Node: Checking for MPFR971880 -Node: POSIX Floating Point Problems973354 -Ref: POSIX Floating Point Problems-Footnote-1977639 -Node: Floating point summary977677 -Node: Dynamic Extensions979867 -Node: Extension Intro981420 -Node: Plugin License982686 -Node: Extension Mechanism Outline983483 -Ref: figure-load-extension983922 -Ref: figure-register-new-function985487 -Ref: figure-call-new-function986579 -Node: Extension API Description988641 -Node: Extension API Functions Introduction990283 -Ref: table-api-std-headers992119 -Node: General Data Types995984 -Ref: General Data Types-Footnote-11004345 -Node: Memory Allocation Functions1004644 -Ref: Memory Allocation Functions-Footnote-11008854 -Node: Constructor Functions1008953 -Node: Registration Functions1012539 -Node: Extension Functions1013224 -Node: Exit Callback Functions1018546 -Node: Extension Version String1019796 -Node: Input Parsers1020459 -Node: Output Wrappers1033180 -Node: Two-way processors1037692 -Node: Printing Messages1039957 -Ref: Printing Messages-Footnote-11041128 -Node: Updating ERRNO1041281 -Node: Requesting Values1042020 -Ref: table-value-types-returned1042757 -Node: Accessing Parameters1043693 -Node: Symbol Table Access1044928 -Node: Symbol table by name1045440 -Ref: Symbol table by name-Footnote-11048464 -Node: Symbol table by cookie1048592 -Ref: Symbol table by cookie-Footnote-11052777 -Node: Cached values1052841 -Ref: Cached values-Footnote-11056377 -Node: Array Manipulation1056530 -Ref: Array Manipulation-Footnote-11057621 -Node: Array Data Types1057658 -Ref: Array Data Types-Footnote-11060316 -Node: Array Functions1060408 -Node: Flattening Arrays1064906 -Node: Creating Arrays1071882 -Node: Redirection API1076649 -Node: Extension API Variables1079482 -Node: Extension Versioning1080193 -Ref: gawk-api-version1080622 -Node: Extension GMP/MPFR Versioning1082353 -Node: Extension API Informational Variables1083981 -Node: Extension API Boilerplate1085054 -Node: Changes from API V11089028 -Node: Finding Extensions1090600 -Node: Extension Example1091159 -Node: Internal File Description1091957 -Node: Internal File Ops1096037 -Ref: Internal File Ops-Footnote-11107387 -Node: Using Internal File Ops1107527 -Ref: Using Internal File Ops-Footnote-11109910 -Node: Extension Samples1110184 -Node: Extension Sample File Functions1111713 -Node: Extension Sample Fnmatch1119362 -Node: Extension Sample Fork1120849 -Node: Extension Sample Inplace1122067 -Node: Extension Sample Ord1125371 -Node: Extension Sample Readdir1126207 -Ref: table-readdir-file-types1127096 -Node: Extension Sample Revout1127901 -Node: Extension Sample Rev2way1128490 -Node: Extension Sample Read write array1129230 -Node: Extension Sample Readfile1131172 -Node: Extension Sample Time1132267 -Node: Extension Sample API Tests1133615 -Node: gawkextlib1134107 -Node: Extension summary1137025 -Node: Extension Exercises1140727 -Node: Language History1141969 -Node: V7/SVR3.11143625 -Node: SVR41145777 -Node: POSIX1147211 -Node: BTL1148591 -Node: POSIX/GNU1149320 -Node: Feature History1155098 -Node: Common Extensions1171144 -Node: Ranges and Locales1172427 -Ref: Ranges and Locales-Footnote-11177043 -Ref: Ranges and Locales-Footnote-21177070 -Ref: Ranges and Locales-Footnote-31177305 -Node: Contributors1177526 -Node: History summary1183479 -Node: Installation1184859 -Node: Gawk Distribution1185803 -Node: Getting1186287 -Node: Extracting1187250 -Node: Distribution contents1188888 -Node: Unix Installation1195368 -Node: Quick Installation1196050 -Node: Shell Startup Files1198464 -Node: Additional Configuration Options1199553 -Node: Configuration Philosophy1201868 -Node: Non-Unix Installation1204237 -Node: PC Installation1204697 -Node: PC Binary Installation1205535 -Node: PC Compiling1205970 -Node: PC Using1207087 -Node: Cygwin1210640 -Node: MSYS1211739 -Node: VMS Installation1212240 -Node: VMS Compilation1213031 -Ref: VMS Compilation-Footnote-11214260 -Node: VMS Dynamic Extensions1214318 -Node: VMS Installation Details1216003 -Node: VMS Running1218256 -Node: VMS GNV1222535 -Node: VMS Old Gawk1223270 -Node: Bugs1223741 -Node: Bug address1224404 -Node: Usenet1227386 -Node: Maintainers1228390 -Node: Other Versions1229651 -Node: Installation summary1236739 -Node: Notes1237941 -Node: Compatibility Mode1238735 -Node: Additions1239517 -Node: Accessing The Source1240442 -Node: Adding Code1241879 -Node: New Ports1248098 -Node: Derived Files1252473 -Ref: Derived Files-Footnote-11258133 -Ref: Derived Files-Footnote-21258168 -Ref: Derived Files-Footnote-31258766 -Node: Future Extensions1258880 -Node: Implementation Limitations1259538 -Node: Extension Design1260721 -Node: Old Extension Problems1261865 -Ref: Old Extension Problems-Footnote-11263383 -Node: Extension New Mechanism Goals1263440 -Ref: Extension New Mechanism Goals-Footnote-11266804 -Node: Extension Other Design Decisions1266993 -Node: Extension Future Growth1269106 -Node: Notes summary1269942 -Node: Basic Concepts1271100 -Node: Basic High Level1271781 -Ref: figure-general-flow1272063 -Ref: figure-process-flow1272748 -Ref: Basic High Level-Footnote-11276049 -Node: Basic Data Typing1276234 -Node: Glossary1279562 -Node: Copying1311400 -Node: GNU Free Documentation License1348943 -Node: Index1374063 +Node: Getline/Variable260703 +Node: Getline/File261854 +Node: Getline/Variable/File263242 +Ref: Getline/Variable/File-Footnote-1264847 +Node: Getline/Pipe264935 +Node: Getline/Variable/Pipe267642 +Node: Getline/Coprocess268777 +Node: Getline/Variable/Coprocess270044 +Node: Getline Notes270786 +Node: Getline Summary273583 +Ref: table-getline-variants274007 +Node: Read Timeout274755 +Ref: Read Timeout-Footnote-1278661 +Node: Retrying Input278719 +Node: Command-line directories279918 +Node: Input Summary280824 +Node: Input Exercises283996 +Node: Printing284724 +Node: Print286558 +Node: Print Examples288015 +Node: Output Separators290795 +Node: OFMT292812 +Node: Printf294168 +Node: Basic Printf294953 +Node: Control Letters296527 +Node: Format Modifiers301691 +Node: Printf Examples307706 +Node: Redirection310192 +Node: Special FD317033 +Ref: Special FD-Footnote-1320201 +Node: Special Files320275 +Node: Other Inherited Files320892 +Node: Special Network321893 +Node: Special Caveats322753 +Node: Close Files And Pipes323702 +Ref: table-close-pipe-return-values330609 +Ref: Close Files And Pipes-Footnote-1331422 +Ref: Close Files And Pipes-Footnote-2331570 +Node: Nonfatal331722 +Node: Output Summary334060 +Node: Output Exercises335282 +Node: Expressions335961 +Node: Values337149 +Node: Constants337827 +Node: Scalar Constants338518 +Ref: Scalar Constants-Footnote-1341042 +Node: Nondecimal-numbers341292 +Node: Regexp Constants344293 +Node: Using Constant Regexps344819 +Node: Standard Regexp Constants345441 +Node: Strong Regexp Constants348629 +Node: Variables351587 +Node: Using Variables352244 +Node: Assignment Options354154 +Node: Conversion356621 +Node: Strings And Numbers357145 +Ref: Strings And Numbers-Footnote-1360208 +Node: Locale influences conversions360317 +Ref: table-locale-affects363075 +Node: All Operators363693 +Node: Arithmetic Ops364322 +Node: Concatenation366828 +Ref: Concatenation-Footnote-1369675 +Node: Assignment Ops369782 +Ref: table-assign-ops374773 +Node: Increment Ops376086 +Node: Truth Values and Conditions379546 +Node: Truth Values380620 +Node: Typing and Comparison381668 +Node: Variable Typing382488 +Ref: Variable Typing-Footnote-1388951 +Ref: Variable Typing-Footnote-2389023 +Node: Comparison Operators389100 +Ref: table-relational-ops389519 +Node: POSIX String Comparison393014 +Ref: POSIX String Comparison-Footnote-1394709 +Ref: POSIX String Comparison-Footnote-2394848 +Node: Boolean Ops394932 +Ref: Boolean Ops-Footnote-1399414 +Node: Conditional Exp399506 +Node: Function Calls401242 +Node: Precedence405119 +Node: Locales408778 +Node: Expressions Summary410410 +Node: Patterns and Actions412983 +Node: Pattern Overview414103 +Node: Regexp Patterns415780 +Node: Expression Patterns416322 +Node: Ranges420103 +Node: BEGIN/END423211 +Node: Using BEGIN/END423972 +Ref: Using BEGIN/END-Footnote-1426708 +Node: I/O And BEGIN/END426814 +Node: BEGINFILE/ENDFILE429128 +Node: Empty432041 +Node: Using Shell Variables432358 +Node: Action Overview434632 +Node: Statements436957 +Node: If Statement438805 +Node: While Statement440300 +Node: Do Statement442328 +Node: For Statement443476 +Node: Switch Statement446647 +Node: Break Statement449033 +Node: Continue Statement451125 +Node: Next Statement452952 +Node: Nextfile Statement455335 +Node: Exit Statement457987 +Node: Built-in Variables460390 +Node: User-modified461523 +Node: Auto-set469290 +Ref: Auto-set-Footnote-1486097 +Ref: Auto-set-Footnote-2486303 +Node: ARGC and ARGV486359 +Node: Pattern Action Summary490572 +Node: Arrays493002 +Node: Array Basics494331 +Node: Array Intro495175 +Ref: figure-array-elements497150 +Ref: Array Intro-Footnote-1499854 +Node: Reference to Elements499982 +Node: Assigning Elements502446 +Node: Array Example502937 +Node: Scanning an Array504696 +Node: Controlling Scanning507718 +Ref: Controlling Scanning-Footnote-1513117 +Node: Numeric Array Subscripts513433 +Node: Uninitialized Subscripts515617 +Node: Delete517236 +Ref: Delete-Footnote-1519988 +Node: Multidimensional520045 +Node: Multiscanning523140 +Node: Arrays of Arrays524731 +Node: Arrays Summary529499 +Node: Functions531592 +Node: Built-in532630 +Node: Calling Built-in533711 +Node: Numeric Functions535707 +Ref: Numeric Functions-Footnote-1539735 +Ref: Numeric Functions-Footnote-2540383 +Ref: Numeric Functions-Footnote-3540431 +Node: String Functions540703 +Ref: String Functions-Footnote-1564561 +Ref: String Functions-Footnote-2564689 +Ref: String Functions-Footnote-3564937 +Node: Gory Details565024 +Ref: table-sub-escapes566815 +Ref: table-sub-proposed568334 +Ref: table-posix-sub569697 +Ref: table-gensub-escapes571238 +Ref: Gory Details-Footnote-1572061 +Node: I/O Functions572215 +Ref: table-system-return-values578683 +Ref: I/O Functions-Footnote-1580763 +Ref: I/O Functions-Footnote-2580911 +Node: Time Functions581031 +Ref: Time Functions-Footnote-1591702 +Ref: Time Functions-Footnote-2591770 +Ref: Time Functions-Footnote-3591928 +Ref: Time Functions-Footnote-4592039 +Ref: Time Functions-Footnote-5592151 +Ref: Time Functions-Footnote-6592378 +Node: Bitwise Functions592644 +Ref: table-bitwise-ops593238 +Ref: Bitwise Functions-Footnote-1599301 +Ref: Bitwise Functions-Footnote-2599474 +Node: Type Functions599665 +Node: I18N Functions602528 +Node: User-defined604179 +Node: Definition Syntax604991 +Ref: Definition Syntax-Footnote-1610678 +Node: Function Example610749 +Ref: Function Example-Footnote-1613671 +Node: Function Calling613693 +Node: Calling A Function614281 +Node: Variable Scope615239 +Node: Pass By Value/Reference618233 +Node: Function Caveats620877 +Ref: Function Caveats-Footnote-1622924 +Node: Return Statement623044 +Node: Dynamic Typing626023 +Node: Indirect Calls626953 +Ref: Indirect Calls-Footnote-1637205 +Node: Functions Summary637333 +Node: Library Functions640038 +Ref: Library Functions-Footnote-1643645 +Ref: Library Functions-Footnote-2643788 +Node: Library Names643959 +Ref: Library Names-Footnote-1647626 +Ref: Library Names-Footnote-2647849 +Node: General Functions647935 +Node: Strtonum Function649038 +Node: Assert Function652060 +Node: Round Function655386 +Node: Cliff Random Function656926 +Node: Ordinal Functions657942 +Ref: Ordinal Functions-Footnote-1661005 +Ref: Ordinal Functions-Footnote-2661257 +Node: Join Function661467 +Ref: Join Function-Footnote-1663237 +Node: Getlocaltime Function663437 +Node: Readfile Function667179 +Node: Shell Quoting669156 +Node: Data File Management670557 +Node: Filetrans Function671189 +Node: Rewind Function675285 +Node: File Checking677194 +Ref: File Checking-Footnote-1678528 +Node: Empty Files678729 +Node: Ignoring Assigns680708 +Node: Getopt Function682258 +Ref: Getopt Function-Footnote-1693727 +Node: Passwd Functions693927 +Ref: Passwd Functions-Footnote-1702766 +Node: Group Functions702854 +Ref: Group Functions-Footnote-1710752 +Node: Walking Arrays710959 +Node: Library Functions Summary713967 +Node: Library Exercises715373 +Node: Sample Programs715838 +Node: Running Examples716608 +Node: Clones717336 +Node: Cut Program718560 +Node: Egrep Program728489 +Ref: Egrep Program-Footnote-1736001 +Node: Id Program736111 +Node: Split Program739791 +Ref: Split Program-Footnote-1743249 +Node: Tee Program743378 +Node: Uniq Program746168 +Node: Wc Program753789 +Ref: Wc Program-Footnote-1758044 +Node: Miscellaneous Programs758138 +Node: Dupword Program759351 +Node: Alarm Program761381 +Node: Translate Program766236 +Ref: Translate Program-Footnote-1770801 +Node: Labels Program771071 +Ref: Labels Program-Footnote-1774422 +Node: Word Sorting774506 +Node: History Sorting778578 +Node: Extract Program780413 +Node: Simple Sed788467 +Node: Igawk Program791541 +Ref: Igawk Program-Footnote-1805872 +Ref: Igawk Program-Footnote-2806074 +Ref: Igawk Program-Footnote-3806196 +Node: Anagram Program806311 +Node: Signature Program809373 +Node: Programs Summary810620 +Node: Programs Exercises811834 +Ref: Programs Exercises-Footnote-1815963 +Node: Advanced Features816054 +Node: Nondecimal Data818044 +Node: Array Sorting819635 +Node: Controlling Array Traversal820335 +Ref: Controlling Array Traversal-Footnote-1828703 +Node: Array Sorting Functions828821 +Ref: Array Sorting Functions-Footnote-1833912 +Node: Two-way I/O834108 +Ref: Two-way I/O-Footnote-1841829 +Ref: Two-way I/O-Footnote-2842016 +Node: TCP/IP Networking842098 +Node: Profiling845216 +Node: Advanced Features Summary854231 +Node: Internationalization856075 +Node: I18N and L10N857555 +Node: Explaining gettext858242 +Ref: Explaining gettext-Footnote-1864134 +Ref: Explaining gettext-Footnote-2864319 +Node: Programmer i18n864484 +Ref: Programmer i18n-Footnote-1869433 +Node: Translator i18n869482 +Node: String Extraction870276 +Ref: String Extraction-Footnote-1871408 +Node: Printf Ordering871494 +Ref: Printf Ordering-Footnote-1874280 +Node: I18N Portability874344 +Ref: I18N Portability-Footnote-1876800 +Node: I18N Example876863 +Ref: I18N Example-Footnote-1880138 +Ref: I18N Example-Footnote-2880211 +Node: Gawk I18N880320 +Node: I18N Summary880969 +Node: Debugger882310 +Node: Debugging883310 +Node: Debugging Concepts883751 +Node: Debugging Terms885560 +Node: Awk Debugging888135 +Ref: Awk Debugging-Footnote-1889080 +Node: Sample Debugging Session889212 +Node: Debugger Invocation889746 +Node: Finding The Bug891132 +Node: List of Debugger Commands897606 +Node: Breakpoint Control898939 +Node: Debugger Execution Control902633 +Node: Viewing And Changing Data905995 +Node: Execution Stack909536 +Node: Debugger Info911173 +Node: Miscellaneous Debugger Commands915244 +Node: Readline Support920306 +Node: Limitations921202 +Node: Debugging Summary923756 +Node: Namespaces925035 +Node: Global Namespace926114 +Node: Qualified Names927512 +Node: Default Namespace928511 +Node: Changing The Namespace929252 +Node: Naming Rules930866 +Node: Internal Name Management932714 +Node: Namespace Example933756 +Node: Namespace And Features936318 +Node: Namespace Summary937753 +Node: Arbitrary Precision Arithmetic939230 +Node: Computer Arithmetic940717 +Ref: table-numeric-ranges944483 +Ref: table-floating-point-ranges944976 +Ref: Computer Arithmetic-Footnote-1945634 +Node: Math Definitions945691 +Ref: table-ieee-formats949007 +Ref: Math Definitions-Footnote-1949610 +Node: MPFR features949715 +Node: FP Math Caution951433 +Ref: FP Math Caution-Footnote-1952505 +Node: Inexactness of computations952874 +Node: Inexact representation953834 +Node: Comparing FP Values955194 +Node: Errors accumulate956435 +Node: Getting Accuracy957868 +Node: Try To Round960578 +Node: Setting precision961477 +Ref: table-predefined-precision-strings962174 +Node: Setting the rounding mode964004 +Ref: table-gawk-rounding-modes964378 +Ref: Setting the rounding mode-Footnote-1968309 +Node: Arbitrary Precision Integers968488 +Ref: Arbitrary Precision Integers-Footnote-1971663 +Node: Checking for MPFR971812 +Node: POSIX Floating Point Problems973286 +Ref: POSIX Floating Point Problems-Footnote-1977571 +Node: Floating point summary977609 +Node: Dynamic Extensions979799 +Node: Extension Intro981352 +Node: Plugin License982618 +Node: Extension Mechanism Outline983415 +Ref: figure-load-extension983854 +Ref: figure-register-new-function985419 +Ref: figure-call-new-function986511 +Node: Extension API Description988573 +Node: Extension API Functions Introduction990215 +Ref: table-api-std-headers992051 +Node: General Data Types995916 +Ref: General Data Types-Footnote-11004277 +Node: Memory Allocation Functions1004576 +Ref: Memory Allocation Functions-Footnote-11008786 +Node: Constructor Functions1008885 +Node: Registration Functions1012471 +Node: Extension Functions1013156 +Node: Exit Callback Functions1018478 +Node: Extension Version String1019728 +Node: Input Parsers1020391 +Node: Output Wrappers1033112 +Node: Two-way processors1037624 +Node: Printing Messages1039889 +Ref: Printing Messages-Footnote-11041060 +Node: Updating ERRNO1041213 +Node: Requesting Values1041952 +Ref: table-value-types-returned1042689 +Node: Accessing Parameters1043625 +Node: Symbol Table Access1044860 +Node: Symbol table by name1045372 +Ref: Symbol table by name-Footnote-11048396 +Node: Symbol table by cookie1048524 +Ref: Symbol table by cookie-Footnote-11052709 +Node: Cached values1052773 +Ref: Cached values-Footnote-11056309 +Node: Array Manipulation1056462 +Ref: Array Manipulation-Footnote-11057553 +Node: Array Data Types1057590 +Ref: Array Data Types-Footnote-11060248 +Node: Array Functions1060340 +Node: Flattening Arrays1064838 +Node: Creating Arrays1071814 +Node: Redirection API1076581 +Node: Extension API Variables1079414 +Node: Extension Versioning1080125 +Ref: gawk-api-version1080554 +Node: Extension GMP/MPFR Versioning1082285 +Node: Extension API Informational Variables1083913 +Node: Extension API Boilerplate1084986 +Node: Changes from API V11088960 +Node: Finding Extensions1090532 +Node: Extension Example1091091 +Node: Internal File Description1091889 +Node: Internal File Ops1095969 +Ref: Internal File Ops-Footnote-11107319 +Node: Using Internal File Ops1107459 +Ref: Using Internal File Ops-Footnote-11109842 +Node: Extension Samples1110116 +Node: Extension Sample File Functions1111645 +Node: Extension Sample Fnmatch1119294 +Node: Extension Sample Fork1120781 +Node: Extension Sample Inplace1121999 +Node: Extension Sample Ord1125303 +Node: Extension Sample Readdir1126139 +Ref: table-readdir-file-types1127028 +Node: Extension Sample Revout1127833 +Node: Extension Sample Rev2way1128422 +Node: Extension Sample Read write array1129162 +Node: Extension Sample Readfile1131104 +Node: Extension Sample Time1132199 +Node: Extension Sample API Tests1133547 +Node: gawkextlib1134039 +Node: Extension summary1136957 +Node: Extension Exercises1140659 +Node: Language History1141901 +Node: V7/SVR3.11143557 +Node: SVR41145709 +Node: POSIX1147143 +Node: BTL1148523 +Node: POSIX/GNU1149252 +Node: Feature History1155030 +Node: Common Extensions1171076 +Node: Ranges and Locales1172359 +Ref: Ranges and Locales-Footnote-11176975 +Ref: Ranges and Locales-Footnote-21177002 +Ref: Ranges and Locales-Footnote-31177237 +Node: Contributors1177458 +Node: History summary1183411 +Node: Installation1184791 +Node: Gawk Distribution1185735 +Node: Getting1186219 +Node: Extracting1187182 +Node: Distribution contents1188820 +Node: Unix Installation1195300 +Node: Quick Installation1195982 +Node: Shell Startup Files1198396 +Node: Additional Configuration Options1199485 +Node: Configuration Philosophy1201800 +Node: Non-Unix Installation1204169 +Node: PC Installation1204629 +Node: PC Binary Installation1205467 +Node: PC Compiling1205902 +Node: PC Using1207019 +Node: Cygwin1210572 +Node: MSYS1211671 +Node: VMS Installation1212172 +Node: VMS Compilation1212963 +Ref: VMS Compilation-Footnote-11214192 +Node: VMS Dynamic Extensions1214250 +Node: VMS Installation Details1215935 +Node: VMS Running1218188 +Node: VMS GNV1222467 +Node: VMS Old Gawk1223202 +Node: Bugs1223673 +Node: Bug address1224336 +Node: Usenet1227318 +Node: Maintainers1228322 +Node: Other Versions1229583 +Node: Installation summary1236671 +Node: Notes1237873 +Node: Compatibility Mode1238667 +Node: Additions1239449 +Node: Accessing The Source1240374 +Node: Adding Code1241811 +Node: New Ports1248030 +Node: Derived Files1252405 +Ref: Derived Files-Footnote-11258065 +Ref: Derived Files-Footnote-21258100 +Ref: Derived Files-Footnote-31258698 +Node: Future Extensions1258812 +Node: Implementation Limitations1259470 +Node: Extension Design1260653 +Node: Old Extension Problems1261797 +Ref: Old Extension Problems-Footnote-11263315 +Node: Extension New Mechanism Goals1263372 +Ref: Extension New Mechanism Goals-Footnote-11266736 +Node: Extension Other Design Decisions1266925 +Node: Extension Future Growth1269038 +Node: Notes summary1269874 +Node: Basic Concepts1271032 +Node: Basic High Level1271713 +Ref: figure-general-flow1271995 +Ref: figure-process-flow1272680 +Ref: Basic High Level-Footnote-11275981 +Node: Basic Data Typing1276166 +Node: Glossary1279494 +Node: Copying1311332 +Node: GNU Free Documentation License1348875 +Node: Index1373995 End Tag Table diff --git a/doc/gawk.texi b/doc/gawk.texi index aef39200..fb982a09 100644 --- a/doc/gawk.texi +++ b/doc/gawk.texi @@ -8521,31 +8521,24 @@ input record and split it up into fields. This is useful if you've finished processing the current record, but want to do some special processing on the next record @emph{right now}. For example: +@c 6/2019: Thanks to Mark Krauze <daburashka@ya.ru> for suggested +@c improvements (the inner while loop). @example # Remove text between /* and */, inclusive @{ - if ((i = index($0, "/*")) != 0) @{ - out = substr($0, 1, i - 1) # leading part of the string - rest = substr($0, i + 2) # ... */ ... - j = index(rest, "*/") # is */ in trailing part? - if (j > 0) @{ - rest = substr(rest, j + 2) # remove comment - @} else @{ - while (j == 0) @{ - # get more text - if (getline <= 0) @{ - print("unexpected EOF or error:", ERRNO) > "/dev/stderr" - exit - @} - # build up the line using string concatenation - rest = rest $0 - j = index(rest, "*/") # is */ in trailing part? - if (j != 0) @{ - rest = substr(rest, j + 2) - break - @} + while ((start = index($0, "/*")) != 0) @{ + out = substr($0, 1, start - 1) # leading part of the string + rest = substr($0, start + 2) # ... */ ... + while ((end = index(rest, "*/")) == 0) @{ # is */ in trailing part? + # get more text + if (getline <= 0) @{ + print("unexpected EOF or error:", ERRNO) > "/dev/stderr" + exit @} + # build up the line using string concatenation + rest = rest $0 @} + rest = substr(rest, end + 2) # remove comment # build up the output line using string concatenation $0 = out rest @} @@ -8553,16 +8546,6 @@ processing on the next record @emph{right now}. For example: @} @end example -@c 8/2014: Here is some sample input: -@ignore -mon/*comment*/key -rab/*commen -t*/bit -horse /*comment*/more text -part 1 /*comment*/part 2 /*comment*/part 3 -no comment -@end ignore - This @command{awk} program deletes C-style comments (@samp{/* @dots{} */}) from the input. It uses a number of features we haven't covered yet, including @@ -8574,8 +8557,29 @@ functions By replacing the @samp{print $0} with other statements, you could perform more complicated processing on the decommented input, such as searching for matches of a regular -expression. (This program has a subtle problem---it does not work if one -comment ends and another begins on the same line.) +expression. + +Here is some sample input: + +@example +mon/*comment*/key +rab/*commen +t*/bit +horse /*comment*/more text +part 1 /*comment*/part 2 /*comment*/part 3 +no comment +@end example + +When run, the output is: + +@example +$ @kbd{awk -f strip_comments.awk example_text} +@print{} monkey +@print{} rabbit +@print{} horse more text +@print{} part 1 part 2 part 3 +@print{} no comment +@end example This form of the @code{getline} command sets @code{NF}, @code{NR}, @code{FNR}, @code{RT}, and the value of @code{$0}. diff --git a/doc/gawktexi.in b/doc/gawktexi.in index 0aaff3e4..47ba071c 100644 --- a/doc/gawktexi.in +++ b/doc/gawktexi.in @@ -8119,31 +8119,24 @@ input record and split it up into fields. This is useful if you've finished processing the current record, but want to do some special processing on the next record @emph{right now}. For example: +@c 6/2019: Thanks to Mark Krauze <daburashka@ya.ru> for suggested +@c improvements (the inner while loop). @example # Remove text between /* and */, inclusive @{ - if ((i = index($0, "/*")) != 0) @{ - out = substr($0, 1, i - 1) # leading part of the string - rest = substr($0, i + 2) # ... */ ... - j = index(rest, "*/") # is */ in trailing part? - if (j > 0) @{ - rest = substr(rest, j + 2) # remove comment - @} else @{ - while (j == 0) @{ - # get more text - if (getline <= 0) @{ - print("unexpected EOF or error:", ERRNO) > "/dev/stderr" - exit - @} - # build up the line using string concatenation - rest = rest $0 - j = index(rest, "*/") # is */ in trailing part? - if (j != 0) @{ - rest = substr(rest, j + 2) - break - @} + while ((start = index($0, "/*")) != 0) @{ + out = substr($0, 1, start - 1) # leading part of the string + rest = substr($0, start + 2) # ... */ ... + while ((end = index(rest, "*/")) == 0) @{ # is */ in trailing part? + # get more text + if (getline <= 0) @{ + print("unexpected EOF or error:", ERRNO) > "/dev/stderr" + exit @} + # build up the line using string concatenation + rest = rest $0 @} + rest = substr(rest, end + 2) # remove comment # build up the output line using string concatenation $0 = out rest @} @@ -8151,16 +8144,6 @@ processing on the next record @emph{right now}. For example: @} @end example -@c 8/2014: Here is some sample input: -@ignore -mon/*comment*/key -rab/*commen -t*/bit -horse /*comment*/more text -part 1 /*comment*/part 2 /*comment*/part 3 -no comment -@end ignore - This @command{awk} program deletes C-style comments (@samp{/* @dots{} */}) from the input. It uses a number of features we haven't covered yet, including @@ -8172,8 +8155,29 @@ functions By replacing the @samp{print $0} with other statements, you could perform more complicated processing on the decommented input, such as searching for matches of a regular -expression. (This program has a subtle problem---it does not work if one -comment ends and another begins on the same line.) +expression. + +Here is some sample input: + +@example +mon/*comment*/key +rab/*commen +t*/bit +horse /*comment*/more text +part 1 /*comment*/part 2 /*comment*/part 3 +no comment +@end example + +When run, the output is: + +@example +$ @kbd{awk -f strip_comments.awk example_text} +@print{} monkey +@print{} rabbit +@print{} horse more text +@print{} part 1 part 2 part 3 +@print{} no comment +@end example This form of the @code{getline} command sets @code{NF}, @code{NR}, @code{FNR}, @code{RT}, and the value of @code{$0}. |