[PATCH] libosmocore[master]: utils/conv_gen.py: improve output formatting

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Vadim Yanitskiy gerrit-no-reply at lists.osmocom.org
Wed Sep 7 15:36:36 UTC 2016


Review at  https://gerrit.osmocom.org/829

utils/conv_gen.py: improve output formatting

Change-Id: I95256c4ad402a3c088bdb6c5a5cda8b17c31881c
---
M src/gsm/Makefile.am
M utils/conv_gen.py
2 files changed, 43 insertions(+), 5 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/29/829/1

diff --git a/src/gsm/Makefile.am b/src/gsm/Makefile.am
index 9a9d96f..d367c89 100644
--- a/src/gsm/Makefile.am
+++ b/src/gsm/Makefile.am
@@ -35,3 +35,5 @@
 # Convolutional codes generation
 gsm0503_conv.c:
 	$(AM_V_GEN)python2 $(top_srcdir)/utils/conv_gen.py
+
+CLEANFILES = gsm0503_conv.c
diff --git a/utils/conv_gen.py b/utils/conv_gen.py
index 38ea63b..5a519bc 100644
--- a/utils/conv_gen.py
+++ b/utils/conv_gen.py
@@ -129,17 +129,30 @@
 		return ns, nb
 
 	def _print_term(self, fi, num_states, pack = False):
+		# Up to 12 numbers should be placed per line
+		counter = 0
 		d = []
+
 		for state in range(num_states):
 			if pack:
 				x = pack(self.next_term_output(state))
 			else:
 				x = self.next_term_state(state)
 
-			d.append("%d, " % x)
-		print >>fi, "\t%s" % ''.join(d)
+			if counter == 0:
+				fi.write("\t")
+			elif counter % 12 == 0:
+				fi.write("\n\t")
+
+			fi.write("%3d, " % x)
+			counter += 1
+
+		fi.write("\n")
 
 	def _print_x(self, fi, num_states, pack = False):
+		# Up to 4 blocks should be placed per line
+		counter = 0
+
 		for state in range(num_states):
 			if pack:
 				x0 = pack(self.next_output(state, 0))
@@ -148,7 +161,30 @@
 				x0 = self.next_state(state, 0)
 				x1 = self.next_state(state, 1)
 
-			print >>fi, "\t{ %2d, %2d }," % (x0, x1)
+			if counter == 0:
+				fi.write("\t")
+			elif counter % 4 == 0:
+				fi.write("\n\t")
+
+			fi.write("{ %2d, %2d }, " % (x0, x1))
+			counter += 1
+
+		fi.write("\n")
+
+	def _print_puncture(self, fi):
+		# Up to 12 numbers should be placed per line
+		counter = 0
+
+		for p in self.puncture:
+			if counter == 0:
+				fi.write("\t")
+			elif counter % 12 == 0:
+				fi.write("\n\t")
+
+			fi.write("%3d, " % p)
+			counter += 1
+
+		fi.write("\n")
 
 	def gen_tables(self, pref, fi):
 		pack = lambda n: \
@@ -173,10 +209,10 @@
 			self._print_term(fi, num_states, pack)
 			print >>fi, "};"
 
+		# Write puncture if preset
 		if len(self.puncture):
 			print >>fi, "\nstatic const int %s_puncture[] = {" % self.name
-			for p in self.puncture:
-				print >>fi, "\t%d," % p
+			self._print_puncture(fi)
 			print >>fi, "};"
 
 		# Write description as a multi-line comment

-- 
To view, visit https://gerrit.osmocom.org/829
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I95256c4ad402a3c088bdb6c5a5cda8b17c31881c
Gerrit-PatchSet: 1
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Owner: Vadim Yanitskiy <axilirator at gmail.com>



More information about the gerrit-log mailing list