converting irregular columns to neat columns

2 views
Skip to first unread message

Larry

unread,
Nov 13, 2009, 4:58:43 PM11/13/09
to GoogleSemWare TSE, TsePro
// spread irregular columns into neat columns

<ctrlshift x><s> execmacro("jigspreadcol")

/***
This macro will divide the data inside a marked column block into
separate left-aligned columns. The original data does not have to be
left-aligned...the macro will find it and fix it up.

The data can be names or text separated by a space, or delimited data
separated by a chosen delimiter (the delimiter will remain.)

The resulting new columns evenly push the data to the right of the
original marked column block if necessary.

Assumptions:
1. that the marked column block completely encloses all of the data to
be separated into columns;
2. that multiple contiguous spaces are not considered multiple
delimiters and are reduced to one space;
3. that multiple contiguous non-space delimiters ARE considered
delimiters and will become columns

The macro processes the originally marked column block then replaces it
with the newly formated column block at the same location.

How to Use:
1. mark the 'messy' column, being sure to include all parts of the data
within the block;
2. execute this macro;
3. the macro asks for the delimiter (separation) character between the
data parts on each line; the default is a space, but any other single
ascii character can be entered;
4. the macro produces the new columns and leaves them marked.

If you are unhappy with the reslut, and if you have TSE's UnDo turned
on, you can recover the original formatting before the macro changed it.

The macro will work on ANY text within the boundaries of the marked
column block, including straight text.

WARNING: This macro deletes the originally marked column block and
replaces it with the newly formatted column block containing the same
information. Be sure you have a backup copy of your file or have UnDo()
turned on so you can recover your original file.

***/

proc main()

string mrkr[1]=" "
string mrkr2[1]=""
string a[255]=""
string b[1]=""

integer ob=0
integer tb=0
integer tb1=0

integer i=0
integer j=0
integer n=0
integer ll=1
integer nt=0

if isblockmarked()==_column_
and ask("Separation Character, ESC=Quit",mrkr)
and length(mrkr)
i=128
repeat
i=i+1
if lfind(chr(i),"gl")==0
mrkr2=chr(i)
endif
until mrkr2<>""
pushblock()
gotoblockbegin()
ob=getbufferid()
tb=createtempbuffer()
copyblock()
unmarkblock()
begfile()
if mrkr==" "
while lreplace(" "," ","ing")
endwhile
endif

// get most tokens
for i=1 to numlines()
gotoline(i)
n=numtokens(gettext(1,currlinelen()),mrkr)
if n>nt
nt=n
endif
endfor
begfile()
tb1=createtempbuffer()

// copy the data to the new format
for i=1 to nt // column by column
gotobufferid(tb)
begfile()
for j=1 to numlines() // line by line
gotobufferid(tb)
gotoline(j)
a=trim(gettext(1,currlinelen()))
gotobufferid(tb1)
gotoline(j)
gotopos(ll)
b=""
if mrkr<>" " and i<>1
b=mrkr
endif
inserttext(b+trim(gettoken(a,mrkr,i)))
if i==1
addline()
endif
endfor // j
ll=longestlineinbuffer()+2
endfor // i

// put in right push column
begfile()
markcolumn(1,ll,numlines(),ll)
fillblock(mrkr2)
gotobufferid(ob)
popblock()
gotoblockbegin()
delblock()
gotobufferid(tb1)
markcolumn(1,1,numlines(),ll+1)
gotobufferid(ob)
copyblock()
lreplace(mrkr2," ","ingl")
if tb
abandonfile(tb)
endif
if tb1
abandonfile(tb1)
endif
sound(9000,10)
message("Finished.")
else
sound(50,20)
warn("No block pt Cancelled. Ending.")
endif

end

Reply all
Reply to author
Forward
0 new messages