summaryrefslogtreecommitdiff
path: root/tools/aligncsv.py
diff options
context:
space:
mode:
authorBen Longbons <b.r.longbons@gmail.com>2011-09-16 14:36:23 -0700
committerBen Longbons <b.r.longbons@gmail.com>2011-09-16 14:48:22 -0700
commited81f91ac3c470e00df0d5c5cf9c274ce30f47b3 (patch)
treec4a59cd3e42a717f611be3acef3bf0009dc5192c /tools/aligncsv.py
parentbfc8f192f99e6afcb5b0910f8800a76b85910e73 (diff)
downloadserverdata-ed81f91ac3c470e00df0d5c5cf9c274ce30f47b3.tar.gz
serverdata-ed81f91ac3c470e00df0d5c5cf9c274ce30f47b3.tar.bz2
serverdata-ed81f91ac3c470e00df0d5c5cf9c274ce30f47b3.tar.xz
serverdata-ed81f91ac3c470e00df0d5c5cf9c274ce30f47b3.zip
Reimplement aligncsv in C++ instead of python.
The main advantage of the new one is that it properly handles {script arg1, arg2;}
Diffstat (limited to 'tools/aligncsv.py')
-rwxr-xr-xtools/aligncsv.py88
1 files changed, 0 insertions, 88 deletions
diff --git a/tools/aligncsv.py b/tools/aligncsv.py
deleted file mode 100755
index 54bcd9d4..00000000
--- a/tools/aligncsv.py
+++ /dev/null
@@ -1,88 +0,0 @@
-#!/usr/bin/python
-# this formats a csv file to a serious whitespace intended format.
-
-import os
-import sys
-
-tabs=True
-additionalspaces = 5
-
-fname = sys.argv[1]
-if not os.path.exists(fname):
- print "that file doesn't exist"
- exit(0);
-
-f=open(fname,"r");
-lines=f.readlines()
-f.close();
-length=0
-
-for line in lines:
- length=max(length, len(line.split(",")))
-
-print "# number of entries =",length
-
-
-#setup text array
-textarray=range(len(lines)+1)
-for x in range(len(lines)+1):
- textarray[x] = range(length)
-
-for x in range(length):
- textarray[-1][x] = 0
-
-#find the longest entry in each line in each position
-for lineno in range(len(lines)):
- if not lines[lineno].strip().startswith("//") or lines[lineno].strip().startswith("//id"):
- sp=lines[lineno].split(",")
- for pieceno in range(len(sp)):
- sp[pieceno] = sp[pieceno].strip() + "," #for the comma add a char
- textarray[-1][pieceno] = max(len(sp[pieceno]),textarray[-1][pieceno])
-
-if tabs:
- #make it divisable by 8 (tabs work then)
- for pieceno in range(length):
- if (textarray[-1][pieceno] %8) !=0:
- textarray[-1][pieceno] = (((textarray[-1][pieceno])/8)*8)+8
-
-for lineno in range(len(lines)):
- if not lines[lineno].strip().startswith("//") or lines[lineno].strip().startswith("//id"):
- sp=lines[lineno].split(",")
- for pieceno in range(length):
- textarray[lineno][pieceno] = ""
- if pieceno<len(sp):
- sp[pieceno]= sp[pieceno].strip()
- if pieceno<len(sp)-1:
- sp[pieceno]= sp[pieceno] + ","
-
- if (tabs):
- n=(textarray[-1][pieceno]-len(sp[pieceno]))
- textarray[lineno][pieceno] = sp[pieceno]
- if (n%8) != 0:
- textarray[lineno][pieceno] += "\t"*((n/8)+1)
- else:
- textarray[lineno][pieceno] += "\t"*((n/8))
- else:
- n=(textarray[-1][pieceno]-len(sp[pieceno])+additionalspaces)
- textarray[lineno][pieceno] = " "*(n) + sp[pieceno]
- else:
- for pieceno in range(length):
- textarray[lineno][pieceno] = ""
- textarray[lineno][0]=lines[lineno].strip()
-
-
-fname = sys.argv[2]
-if not os.path.exists(fname):
- print "that file doesn't exist"
- exit(0);
-else:
- f=open(fname,"w");
- for line in textarray[:-1]:
- for piece in line:
- f.write(piece)
- f.write("\n")
- f.close()
-
-
-
-