[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[SCM] gawk branch, feature/l2p, updated. gawk-4.1.0-5929-g3ea602d7
From: |
Arnold Robbins |
Subject: |
[SCM] gawk branch, feature/l2p, updated. gawk-4.1.0-5929-g3ea602d7 |
Date: |
Mon, 30 Jun 2025 22:18:06 -0400 (EDT) |
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "gawk".
The branch, feature/l2p has been updated
via 3ea602d7731678dce713ddd5c9599312fc959782 (commit)
from 9b274d25b576caf207642d4d196978b448a5aa09 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
http://git.sv.gnu.org/cgit/gawk.git/commit/?id=3ea602d7731678dce713ddd5c9599312fc959782
commit 3ea602d7731678dce713ddd5c9599312fc959782
Author: Arnold D. Robbins <arnold@skeeve.com>
Date: Mon Jun 30 22:17:37 2025 -0400
Basic version of l2p.awk now working.
diff --git a/helpers/l2p.awk b/helpers/l2p.awk
index a0abb9e9..7e292b29 100644
--- a/helpers/l2p.awk
+++ b/helpers/l2p.awk
@@ -10,6 +10,9 @@
# arnold@skeeve.com
# June 2025
+# There are lots of global variables here. Since it's a small script, that's
+# OK, but things might be cleaner if functions could do pass by reference.
+
@load "ordchr"
BEGIN {
@@ -51,6 +54,9 @@ function reset_output()
Direction = "L2R" # initial direction, left to right
Left = "" # left side of output
Right = "" # right side of output
+ Format_count = 1 # for use in %<n>$xyz<format>
+ delete Chars # Input line after splitting
+ Len = 0 # Length of input line
}
# is_space --- check if a character is white space
@@ -67,24 +73,73 @@ function is_punct(char)
return char ~ /[[:punct:]]/
}
+# parse_and_build_format --- parse a printf format and revise it as needed
+
+function parse_and_build_format(start, lastpos, i, resultstpos)
+{
+ # input is something like %...s or `%...s'
+
+ if (Chars[start] == "`") {
+ result = "`%" Format_count++ "$"
+ start += 2
+ for (i = start; Chars[i] != "'"; i++) {
+ result = result Chars[i]
+ }
+ lastpos[1] = i
+ result = result "'"
+ } else {
+ result = "%" Format_count++ "$"
+ for (i = ++start; ! (Chars[i] in Conversions); i++) {
+ result = result Chars[i]
+ }
+ lastpos[1] = i
+ result = result Chars[i]
+ }
+
+ return result
+}
+
# build_output --- build the output line
-function build_output(chars, len, i)
+function build_output( i, new_format, lastpos)
{
- for (i = 1; i <= len; i++) {
- # if (chars[i] == "%") {
- # } else
- if (is_hebrew(chars[i]) || ord(chars[i]) > 127) {
+ for (i = 1; i <= Len; i++) {
+ delete lastpos
+ if (Chars[i] == "`" && Chars[i+1] == "%") {
+ new_format = parse_and_build_format(i, lastpos)
+ i = lastpos[1]
+ if (Direction == "R2L")
+ Right = new_format Right
+ else
+ Left = Left new_format
+ continue
+ } else if (Chars[i] == "%") {
+ if (Chars[i+1] == " " || Chars[i+1] == "%") { # pass
through
+ if (Direction == "R2L")
+ Right = Chars[i] Chars[i+1] Right
+ else
+ Left = Left Chars[i] Chars[i+1]
+ i++
+ } else {
+ new_format = parse_and_build_format(i, lastpos)
+ i = lastpos[1]
+ if (Direction == "R2L")
+ Right = new_format Right
+ else
+ Left = Left new_format
+ }
+ continue
+ } else if (is_hebrew(Chars[i]) || ord(Chars[i]) > 127) {
Direction = "R2L"
- Right = chars[i] Right
- } else if (is_space(chars[i]) || is_punct(chars[i])) {
+ Right = Chars[i] Right
+ } else if (is_space(Chars[i]) || is_punct(Chars[i])) {
if (Direction == "R2L")
- Right = chars[i] Right
+ Right = Chars[i] Right
else
- Left = Left chars[i]
+ Left = Left Chars[i]
} else {
Direction = "L2R"
- Left = Left chars[i]
+ Left = Left Chars[i]
}
}
}
@@ -107,13 +162,13 @@ Processing == TRUE {
} else
key = ""
- len = length($0)
+ Len = length($0)
if (substr($0, 1, 1) == "\"")
- $0 = substr($0, 2, len-2)
+ $0 = substr($0, 2, Len-2)
- len = split($0, chars, "") # get indvidual characters
+ Len = split($0, Chars, "") # get indvidual characters
- build_output(chars, len)
+ build_output()
if (key)
printf("%s ", key)
-----------------------------------------------------------------------
Summary of changes:
helpers/l2p.awk | 83 +++++++++++++++++++++++++++++++++++++++++++++++----------
1 file changed, 69 insertions(+), 14 deletions(-)
hooks/post-receive
--
gawk
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [SCM] gawk branch, feature/l2p, updated. gawk-4.1.0-5929-g3ea602d7,
Arnold Robbins <=