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: Character: Count: Total: How to count the total amount of characters in a block?

Nov 12th, 2006 09:13
Knud van Eeden,


----------------------------------------------------------------------
--- Knud van Eeden --- 12 November 2020 - 03:12 pm -------------------
TSE: Block: Character: Count: Total: How to count the total amount of 
characters in a block?
===
Method: Count all characters, by visiting each line in the block, 
getting its linesize
        and adding this to counter. Use this for lineblocks only
--- cut here: begin --------------------------------------------------
FORWARD INTEGER PROC FNBlockGetCharacterTotalLineSimpleI()
FORWARD PROC Main()
// --- MAIN --- //
PROC Main()
 Message( FNBlockGetCharacterTotalLineSimpleI() ) // gives e.g. 410 
characters totally in the currently marked block
END
<F12> Main()
// --- LIBRARY --- //
// library: block: get: character: total: line: simple 
(filenamemacro=getbllsi.s) [kn, ri, su, 12-11-2020 17:11:30]
INTEGER PROC FNBlockGetCharacterTotalLineSimpleI()
 INTEGER I = 0
 INTEGER downB = TRUE
 IF NOT IsBlockMarked()
  Warn( "Please mark a block" )
  RETURN( 0 )
 ENDIF
 PushPosition()
 GotoBlockBegin()
 WHILE ( IsCursorInBlock() ) AND ( downB )
  I = I + CurrLineLen()
  downB = Down()
 ENDWHILE
 PopPosition()
 RETURN( I )
END
--- cut here: end ----------------------------------------------------
===
Method: Count all characters, by visiting each line in the block,
        getting its linesize and adding this to counter. Use this for
        lineblocks only. You can use this method both for line blocks
        and column blocks.
===
--- cut here: begin --------------------------------------------------
FORWARD INTEGER PROC FNBlockGetCharacterTotalLineBufferSimpleI()
FORWARD PROC Main()
// --- MAIN --- //
PROC Main()
 Message( FNBlockGetCharacterTotalLineBufferSimpleI() ) // gives e.g. 
410 characters totally in the currently marked block
END
<F12> Main()
// --- LIBRARY --- //
// library: block: get: character: total: line: buffer: simple 
(filenamemacro=getblbsi.s) [kn, ri, su, 12-11-2020 17:38:40]
INTEGER PROC FNBlockGetCharacterTotalLineBufferSimpleI()
 INTEGER I = 0
 INTEGER downB = TRUE
 INTEGER bufferI = 0
 IF NOT IsBlockMarked()
  Warn( "Please mark a block" )
  RETURN( 0 )
 ENDIF
 PushPosition()
 PushBlock()
 Copy()
 bufferI = CreateTempBuffer()
 IF ( bufferI == 0 )
  Warn( "could not create a temporary buffer" )
  RETURN( 0 )
 ENDIF
 IF GotoBufferId( bufferI )
  Paste()
  GotoBlockBegin()
  WHILE ( IsCursorInBlock() ) AND ( downB )
   I = I + CurrLineLen()
   downB = Down()
  ENDWHILE
  AbandonFile( bufferI )
 ELSE
  Warn( "could not goto the temporary buffer" )
  RETURN( 0 )
 ENDIF
 PopPosition()
 PopBlock()
 RETURN( I )
END
--- cut here: end ----------------------------------------------------
---
Method: Count all characters, by visiting each character one by one in
        the block and increasing a corresponding counter
--- cut here: begin --------------------------------------------------
FORWARD INTEGER PROC FNBlockGetCharacterTotalOneSimpleI()
FORWARD PROC Main()
// --- MAIN --- //
PROC Main()
 Message( FNBlockGetCharacterTotalOneSimpleI() ) // gives e.g. 410 
characters totally in the currently marked block
END
<F12> Main()
// --- LIBRARY --- //
// library: block: get: character: total: simple 
(filenamemacro=getbltsi.s) [kn, ri, su, 12-11-2020 15:21:47]
INTEGER PROC FNBlockGetCharacterTotalOneSimpleI()
 INTEGER I = 0
 INTEGER gotoNextCharacterB = TRUE
 IF NOT IsBlockMarked()
  Warn( "Please mark a block" )
  RETURN( 0 )
 ENDIF
 PushPosition()
 GotoBlockBegin()
 WHILE ( IsCursorInBlock() ) AND ( gotoNextCharacterB )
  // you choose to not count end of line characters, so subtract 2 
characters
  IF ( CurrChar() >= 0 )
   I = I + 1
  ENDIF
  gotoNextCharacterB = NextChar()
 ENDWHILE
 PopPosition()
 RETURN( I )
END
--- cut here: end ----------------------------------------------------
---
Method: Count all characters by copying the block to a temporary
        buffer, saving it to disk, and getting the filesize of that
        diskfile
This method will give only an indication of the total amount of
characters because of different way of counting, and disk storage
conditions, but it should be a rather fast method.
===
Internet: see also:
---
TSE: Block: Save: File: Size: How to get the filesize of a block saved 
on disk?
http://www.faqts.com/knowledge_base/view.phtml/aid/42972/fid/898
----------------------------------------------------------------------