Example XMAS.PRT
; XMAS
;
; Program for Proteus
;
; (C) 2000-2004 Simone Zanella Productions
;
; Print a text in shape of a tree, with a single character at the top, 3 characters in the
; second row, 5 characters in the third, etc.

#!proteus -z

IF LT(ARGC, 6)
  CONSOLELN "Syntax: " ARGV(1) " " ARGV(2) " source.txt destination.txt"
  CONSOLELN ""
  CONSOLELN "Purpose: writes to destination.txt the contents of source.txt,"
  CONSOLELN "in shape of a tree."
  ABORT 0
FI

; Load file to a string
S = FLOAD(ARGV(5))
IF ISEMPTY(S)
  CONSOLELN "File " ARGV(5) " not found or empty!"
  ABORT 1
FI

; Open destination
D = FOPEN(ARGV(6), 28)  
IF EQ(D, -1)
  CONSOLELN "Could not create " ARGV(6) "!"
  ABORT 2
FI

; Replace end-of-line with a single blank
STRTRAN(@S, EOL, " ")

; Replace multiple blanks with a single blank
P = STRSTR(S, "  ")
WHILE NEQ(P, 0)
  STRTRAN(@S, "  ", " ")
  P = STRSTR(S, "  ")
LOOP

; Create tree rows
Q = QUEUENEW()
MAXLEN = 1
WHILE STRLEN(S)
  ENQUEUE(Q, LEFT(S, MAXLEN))
  RESTFROM(@S, INC(MAXLEN))  
  ADD(@MAXLEN, 2)  
LOOP

; Print tree
WHILE QUEUELEN(Q)
  FWRITELN(D, RTRIM(CENTER(DEQUEUE(Q), MAXLEN), " "))
LOOP
QUEUEFREE(Q)
FCLOSE(D)

ABORT 0  
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