Example ASCSTAT.PRT
; ASCSTAT
;
; Program for Proteus
;
; (C) 1998-2004 Simone Zanella Productions
;
; This program displays a graph (LENGTH columns wide) that represents
; the relative frequency of characters found in the specified file; 
; output is written to console.

; Implicit parameters: NULL input and output

;!proteus -z

Width = 53
IF ISEMPTY(ARGV(5))
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " [filename [length]]"
  CONSOLELN ""
  CONSOLELN "Purpose: displays to console the relative frequency of characters found"
  CONSOLELN "into \"filename\"; \"length\" sets the width of the graph"
  CONSOLELN "in columns (default= " Width ")"
  ABORT 0
FI
FileName = ARGV(5)
IF ISNOTEMPTY(ARGV(6))
  Width = ARGV(6)
FI
; Open filename
FH = FOPEN(FileName, 1)
IF EQ(FH, -1)
  CONSOLELN "File " FileName " not found."
  ABORT 0
FI
; Create an array to count occurrences of each character
VH = VECNEW(256)
FOR X = 1 TO 256
  VECSET(VH, X, 0)
NEXT
FS = FSIZE(FH)
; Process the file
WHILE NOT(FEOF(FH))
  S = FREAD(FH, 2048)
  STRTRAVERSE(S, UpdateTable)
LOOP
FCLOSE(FH)
; Determine the highest number of repetitions
Max = 0
FOR X = 1 TO 256
  IF LT(Max, VECGET(VH, X))
    Max = VECGET(VH, X)
  FI
NEXT
IF EQ(Max, 0)
  CONSOLELN "File is empty."
  ABORT 0
FI
; Determine the length of a single element of the graph
IF GT(Max, Width)
  Increment = FDIV(Max, Width)
ELSE
  Increment = 1
FI
CONSOLELN "Character frequencies for " FileName \
          " (" DATE() ", " RTRIM(TIME(), " ") "):"
CONSOLELN "CHR  ASC  NUMBER  FREQ"
FS = FDIV(FS, 100)
FOR X = 1 TO 256
  IF ISET(N, VECGET(VH, X))
    CONSOLELN PrintChar(DEC(X)) " " PADL(X, 3, "0") "  " \
              PADR(N, 8, " ") PADR(PFORMAT("04.2lf", FDIV(N, FS)) \
              "%", 8, " ") REPLICATE("+", FDIV(N, Increment))
  FI
NEXT
ABORT 0


FUNCTION UpdateTable(car, dummy)

  i = ASC(car)
  VECSET(_VH, i, INC(VECGET(_VH, i)))
RETURN 0


FUNCTION PrintChar(x)

  IF GE(x, 32)
    RETURN CHR(x) "   "
  FI
RETURN "0x" PFORMAT("02X", x)
Samples index Next example Previous example Contents Index
Midnight Lake iPhone Case Black Women Shoes Black Flat Shoes Leather Flats Black Patent Ballerinas Black Ballet Shoes Casual Shoes Black Shoes Women Balle Record Player Cufflinks Best iPhone XR Clear Cases iPhone XS/XS Max Leather Cases Sale Best iPhone 8/8 Plus Silicone Cases iPhone 7/7 Plus Cases & Screen Protector New Cases For iPhone 6/6 Plus iPhone 8 Case Sale iPhone Xr Case Online iPhone 7 Case UK Online iPhone X Case UK Sale iPhone X Case Deals iPhone Xs Case New Case For iPhone Xr UK Online Case For iPhone 8 UK Outlet Fashion Silver Cufflinks For Men Best Mens Cufflinks Outlet Online The Gold Cufflinks Shop Online Cheap Shirt Cufflinks On Sale Nice Wedding Cufflinks UK Online Top Black Cufflinks UK Online Mens Cufflinks Online Silver Cufflinks For Men Men Cufflinks UK Sale Gold Cufflinks UK Online Gold Cufflinks UK Silver Cufflinks UK Shirt Cufflinks Discount Online Mens Cufflinks Deals & Sales Girls Shoes For Dance Fashion Ballet Dance Shoes Best Ballet Flats Shoes UK Online Cheap Ballet Pointe Shoes UK Online Best Ballet Shoes Outlet Best Dance Shoes Sale Cheap Ballet Flats Sale UK Best Pointe Shoes Online UK Ballet Dance Shoes UK Shoes For Dance UK Best Ballet Slippers Shop Best Yoga Shoes Hotsell