Skip to content

Commit

Permalink
Update sdwrap.py
Browse files Browse the repository at this point in the history
  • Loading branch information
RedYetiDev authored Aug 13, 2024
1 parent 88d0e1d commit 5a70f4a
Showing 1 changed file with 51 additions and 51 deletions.
102 changes: 51 additions & 51 deletions tools/zos/sdwrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,65 +4,65 @@
import sys

def wrap(args):
firstline = True
while (line := args.input.read(72)):
if line.endswith('\n'):
if firstline:
outstr = f"{line}"
else:
outstr = f" {line}"
firstline = True
else:
if firstline:
outstr = f"{line:<71}*\n"
firstline = False
else:
outstr = f" {line:<70}*\n"
line = line[-1] + args.input.read(70)
args.output.write(outstr)
return 0
firstline = True
while (line := args.input.read(72)):
if line.endswith('\n'):
if firstline:
outstr = f"{line}"
else:
outstr = f" {line}"
firstline = True
else:
if firstline:
outstr = f"{line:<71}*\n"
firstline = False
else:
outstr = f" {line:<70}*\n"
line = line[-1] + args.input.read(70)
args.output.write(outstr)
return 0

def unwrap(args):
firstline = True
for line in args.input:
if len(line) > 80:
print("Error: input line invalid (longer than 80 characters)", file=sys.stderr)
return 1
if not firstline and line[0] != ' ':
print("Error: continuation line does not start with a blank", file=sys.stderr)
return 1
firstline = True
for line in args.input:
if len(line) > 80:
print("Error: input line invalid (longer than 80 characters)", file=sys.stderr)
return 1
if not firstline and line[0] != ' ':
print("Error: continuation line does not start with a blank", file=sys.stderr)
return 1

if len(line) > 71 and line[71] == '*':
if firstline:
args.output.write(line[:71])
firstline = False
else:
args.output.write(line[1:71])
else:
if firstline:
args.output.write(line)
else:
args.output.write(line[1:])
firstline = True
return 0
if len(line) > 71 and line[71] == '*':
if firstline:
args.output.write(line[:71])
firstline = False
else:
args.output.write(line[1:71])
else:
if firstline:
args.output.write(line)
else:
args.output.write(line[1:])
firstline = True
return 0

def main():
parser = argparse.ArgumentParser(description="Wrap sidedeck source to card formats")
parser.add_argument("-u", "--unwrap", help="Unwrap sidedeck cards to source formats instead", action="store_true")
parser.add_argument("-i", "--input", help="Input filename, defaults to stdin", default=None)
parser.add_argument("-o", "--output", help="Output filename, defaults to stdout", default=None)
parser = argparse.ArgumentParser(description="Wrap sidedeck source to card formats")
parser.add_argument("-u", "--unwrap", help="Unwrap sidedeck cards to source formats instead", action="store_true")
parser.add_argument("-i", "--input", help="Input filename, defaults to stdin", default=None)
parser.add_argument("-o", "--output", help="Output filename, defaults to stdout", default=None)

args = parser.parse_args()
args = parser.parse_args()

with open(args.input, 'r') if args.input else sys.stdin as infile, \
open(args.output, 'w') if args.output else sys.stdout as outfile:
with open(args.input, 'r') if args.input else sys.stdin as infile, \
open(args.output, 'w') if args.output else sys.stdout as outfile:

args.input = infile
args.output = outfile
args.input = infile
args.output = outfile

if args.unwrap:
return unwrap(args)
return wrap(args)
if args.unwrap:
return unwrap(args)
return wrap(args)

if __name__ == '__main__':
sys.exit(main())
sys.exit(main())

0 comments on commit 5a70f4a

Please sign in to comment.