1
0
mirror of synced 2024-06-02 16:58:05 +02:00

Option »base« added, »:« allowed in options

?base=16 for hexadecimal
?base=8 for octal (one byte)
This commit is contained in:
Sebastian Walz 2018-10-21 01:11:51 +02:00 committed by GitHub
parent d450da7d8a
commit d491e976a3
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -94,6 +94,7 @@ class Protocol():
self.hdr_char_fill_even="-" # Fill character for border even positions self.hdr_char_fill_even="-" # Fill character for border even positions
self.hdr_char_sep="|" # Field separator character self.hdr_char_sep="|" # Field separator character
self.bits_per_line=32 # Number of bits per line self.bits_per_line=32 # Number of bits per line
self.base_of_top_tens=10 # Base of top numbers
self.do_print_top_tens=True # True: print top numbers for bit tens self.do_print_top_tens=True # True: print top numbers for bit tens
self.do_print_top_units=True # True: print top numbers for bit units self.do_print_top_units=True # True: print top numbers for bit units
self.field_list=[] # Header fields to be printed out self.field_list=[] # Header fields to be printed out
@ -138,11 +139,15 @@ class Protocol():
opts=opts.split(",") opts=opts.split(",")
for opt in opts: for opt in opts:
try: try:
var, value = opt.split("=") var, value = opt.replace(':','=').split("=")
if var.lower()=="bits": if var.lower()=="bits":
self.bits_per_line=int(value) self.bits_per_line=int(value)
if self.bits_per_line<=0: if self.bits_per_line<=0:
raise ProtocolException("FATAL: Invalid value for 'bits' option (%s)" % value) raise ProtocolException("FATAL: Invalid value for 'bits' option (%s)" % value)
elif var.lower()=="base":
self.base_of_top_tens=int(value)
if self.base_of_top_tens<=0 or self.base_of_top_tens>16:
raise ProtocolException("FATAL: Invalid value for 'base' option (%s)" % value)
elif var.lower()=="numbers": elif var.lower()=="numbers":
if value.lower() in ["0", "n", "no", "none", "false"]: if value.lower() in ["0", "n", "no", "none", "false"]:
self.do_print_top_tens=False self.do_print_top_tens=False
@ -185,14 +190,14 @@ class Protocol():
lines=["", ""] lines=["", ""]
if self.do_print_top_tens is True: if self.do_print_top_tens is True:
for i in range(0, self.bits_per_line): for i in range(0, self.bits_per_line):
if str(i)[-1:]=="0": if i%self.base_of_top_tens==0:
lines[0]+=" %s" % str(i)[0] lines[0]+=" %s" % chars[int(i/self.base_of_top_tens)%self.base_of_top_tens]
else: else:
lines[0]+=" " lines[0]+=" "
lines[0]+="\n" lines[0]+="\n"
if self.do_print_top_units is True: if self.do_print_top_units is True:
for i in range(0, self.bits_per_line): for i in range(0, self.bits_per_line):
lines[1]+=" %s" % str(i)[-1:] lines[1]+=" %s" % chars[i%self.base_of_top_tens]
#lines[1]+="\n" #lines[1]+="\n"
result = "".join(lines) result = "".join(lines)
return result if len(result)>0 else None return result if len(result)>0 else None