[llvm] Add text file support for z/OS back in (PR #209259)
Sean Perry via llvm-commits
llvm-commits at lists.llvm.org
Mon Jul 13 20:52:19 PDT 2026
================
@@ -65,18 +66,32 @@ def run(argv, stdin, stdout, stderr, cwd):
for filename in filenames:
path = filename
- contents = None
if not os.path.isabs(path):
path = os.path.join(cwd, path)
- try:
- with open(path, "rb") as fileToCat:
- contents = fileToCat.read()
- except IOError as error:
- error.filename = filename
- stderr.write(str(error).encode())
- return 1
+
+ contents = None
+ is_text = False
+ if platform.system() == "OS/390":
+ try:
+ with open(path, "r") as fileToCat:
+ contents = fileToCat.read()
+ is_text = True
+ except:
+ pass
+
+ if contents is None:
+ try:
+ with open(path, "rb") as fileToCat:
+ contents = fileToCat.read()
+ except IOError as error:
+ error.filename = filename
+ stderr.write(str(error).encode())
+ return 1
+
if show_nonprinting:
contents = convertToCaretAndMNotation(contents)
+ elif is_text:
+ contents = contents.encode()
----------------
perry-ca wrote:
With the way the code is now the sequence of operations for a text file on z/OS with the --show-nonprinting option is:
1. open the file
2. read the file
3. call the convert function (this calls encode())
4. print the contents
If we called encode() where the is_text flag is set, the sequence would be
1. open the file
2. read the file
3. encode the contents
4. call the convert function (which calls encode() again)
5. print the contents.
I'm thinking of a command like `python cat.py --show-nonprinting text-file`. I'm pretty sure we came across this when first making this change.
https://github.com/llvm/llvm-project/pull/209259
More information about the llvm-commits
mailing list