faqts : Computers : Programming : Languages : Tse : Block

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

Entry

TSE: Block: Line: Length: Maximum: How to get the maximum line length in a marked block? [longest]

Oct 28th, 2006 07:33
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 28 October 2020 - 02:41 pm --------------------
TSE: Block: Line: Length: Maximum: How to get the maximum line length 
in a marked block? [longest]
Using the usual algorithm to find the maximum.
You set the maximum to some minimum value.
Compare that maximum with all the values in the set (in this case all 
lines in the block)
When the maximum is smaller, you replace the maximum with that value.
===
Pseudo code
--- cut here: begin --------------------------------------------------
 Mark manually a block
 set can go down flag to true
 goto first line of the block
 WHILE ( cursor in block ) and ( down )
  if the maximal line length is smaller than the current line length, 
then
  replace the maximal line length with the current line length
  GOTO next line and set down flag to true if you can do that 
successfully
 ENDWHILE
 return the maximal line length
--- cut here: end ----------------------------------------------------
===
--- cut here: begin --------------------------------------------------
 PROC Main()
  INTEGER lineLengthMaxI = 0
  INTEGER lineLengthI = 0
  INTEGER downB = TRUE
  IF NOT IsBlockMarked()
   Warn( "Please mark a block first" )
  ENDIF
  PushPosition()
  GotoBlockBegin()
  WHILE ( IsCursorInBlock() ) AND ( downB )
   lineLengthI = CurrLineLen()
   IF ( lineLengthMaxI < lineLengthI )
    lineLengthMaxI = lineLengthI
   ENDIF
   downB = Down()
  ENDWHILE
  PopPosition()
  Warn( "maximum line length = ", lineLengthMaxI )
 END
 <F12> Main()
--- cut here: end ----------------------------------------------------
===
Or as a function
--- cut here: begin --------------------------------------------------
 INTEGER PROC FNBlockGetLineLengthMaxI()
  INTEGER lineLengthMaxI = 0
  INTEGER lineLengthI = 0
  INTEGER downB = TRUE
  PushPosition()
  GotoBlockBegin()
  WHILE ( IsCursorInBlock() ) AND ( downB )
   lineLengthI = CurrLineLen()
   IF ( lineLengthMaxI < lineLengthI )
    lineLengthMaxI = lineLengthI
   ENDIF
   downB = Down()
  ENDWHILE
  PopPosition()
  RETURN( lineLengthMaxI )
 END
 PROC Main()
  IF NOT IsBlockMarked()
   Warn( "Please mark a block first" )
   RETURN()
  ENDIF
  Warn( "maximum line length = ", FNBlockGetLineLengthMaxI() )
 END
 <F12> Main()
--- cut here: end ----------------------------------------------------
===
If you run this program, after marking a block, it will e.g.
show
 maximum line length = 47
===
Internet: see also:
---
----------------------------------------------------------------------