Jump to content

Align columns: Difference between revisions

Line 9,409:
Further, allow for each word in a column to be either left
justified, right justified, or center justified within its column. be either left
</pre>
 
=={{header|TSE SAL}}==
<lang TSESAL>
INTEGER PROC FNBlockChangeColumnAlignLeftB( INTEGER columnTotalI, INTEGER spaceTotalI, INTEGER buffer1I )
INTEGER B = FALSE
INTEGER downB = TRUE
INTEGER minI = 1
INTEGER I = 0
INTEGER J = 0
INTEGER K = 0
INTEGER L = 0
INTEGER buffer2I = 0
STRING s[255] = ""
INTEGER wordRightB = FALSE
STRING s1[255] = Query( WordSet )
IF ( NOT ( IsBlockInCurrFile() ) ) Warn( "Please mark a block" ) B = FALSE RETURN( B ) ENDIF // return from the current procedure if no block is marked
Set( BREAK, ON )
PushPosition()
PushBlock()
Set( WordSet, ChrSet( "a-zA-Z0-9_,." ) )
PushPosition()
buffer2I = CreateTempBuffer()
PopPosition()
PushPosition()
PushBlock()
DO 100 TIMES
AddLine( "", buffer2I )
ENDDO
PopBlock()
PopPosition()
GotoBlockBegin()
I = minI - 1
WHILE ( ( IsCursorInBlock() ) AND ( downB ) )
IF NOT LFind( "^$", "cgx" )
BegLine()
REPEAT
s = GetWord()
IF NOT ( s == "" )
s = Trim( s )
I = I + 1
IF ( I > columnTotalI )
I = minI
ENDIF
J = Length( s )
PushPosition()
PushBlock()
GotoBufferId( buffer2I )
GotoLine( I )
//
IF ( CurrLineLen() == 0 )
BegLine()
InsertText( Format( Str( J ), " " ), _INSERT_ )
ELSE
K = Val( Trim( GetText( 1, MAXSTRINGLEN ) ) )
IF ( J > K )
BegLine()
DelToEol()
BegLine()
InsertText( Str( J ), _INSERT_ )
ENDIF
ENDIF
PopBlock()
PopPosition()
wordRightB = WordRight()
ENDIF
UNTIL ( s == "" ) OR ( NOT wordRightB )
ENDIF
downB = Down()
ENDWHILE
GotoBlockBegin()
I = minI - 1
L = 1
K = 1
WHILE ( ( IsCursorInBlock() ) AND ( downB ) )
IF NOT LFind( "^$", "cgx" )
BegLine()
REPEAT
B = FALSE
s = GetWord()
IF NOT ( s == "" )
s = Trim( s )
I = I + 1
IF ( I > columnTotalI )
I = minI
K = 1
L = L + 1
ENDIF
//
PushPosition()
PushBlock()
GotoBufferId( buffer2I )
GotoLine( I )
J = Val( Trim( GetText( 1, MAXSTRINGLEN ) ) )
PopPosition()
PopBlock()
PushPosition()
PushBlock()
GotoBufferId( buffer1I )
GotoLine( L )
GotoColumn( K )
InsertText( s, _INSERT_ )
K = K + J + spaceTotalI
PopBlock()
PopPosition()
wordRightB = WordRight()
ENDIF
UNTIL ( s == "" ) OR ( NOT wordRightB )
ENDIF
AddLine( "", buffer1I )
downB = Down()
ENDWHILE
OneWindow()
VWindow()
GotoWindow( 1 )
GotoBufferId( buffer2I )
GotoWindow( 2 )
GotoBufferId( buffer1I )
B = TRUE
Set( WordSet, s1 )
PopPosition()
PopBlock()
RETURN( B )
END
//
PROC Main()
STRING s1[255] = "12" // change this
STRING s2[255] = "2" // change this
INTEGER bufferI = 0
PushPosition()
bufferI = CreateTempBuffer()
PopPosition()
IF ( NOT ( Ask( "block: change: column: align: left: columnTotalI = ", s1, _EDIT_HISTORY_ ) ) AND ( Length( s1 ) > 0 ) ) RETURN() ENDIF
IF ( NOT ( Ask( "block: change: column: align: left: spaceTotalI = ", s2, _EDIT_HISTORY_ ) ) AND ( Length( s2 ) > 0 ) ) RETURN() ENDIF
Message( FNBlockChangeColumnAlignLeftB( Val( s1 ), Val( s2 ), bufferI ) ) // gives e.g. TRUE
GotoBufferId( bufferI )
END
</lang>
{{out}} <pre>
Given a text file of many lines, where fields within a line
are delineated by a single dollar character, write a program that aligns
each column of fields by ensuring that words in each column are
separated by at least one space. Further, allow for each word in
a column to be either left justified, right justified, or center justified
within its column.
</pre>
 
Cookies help us deliver our services. By using our services, you agree to our use of cookies.