Syntax Highlighing:
comments, key words, predefined symbols, class members & methods, functions & classes
# TEXTFILES.sml
# sample script for tutorial Writing Scripts with SML
# demonstrates reading and writing text files
clear();
class FILE infile, outfile;
# set the filenames of input and output text files in the
# same directory as this script
class STRING infilename$ = _context.ScriptDir + "/read.txt";
class STRING outfilename$ = _context.ScriptDir + "/write.txt";
class STRING lineStr;
# open the readtext.txt file for reading
infile = fopen(infilename$, "r");
# open the writetext.txt file for writing; overwrite if existing
outfile = fopen(outfilename$, "w", "ASCII");
# get each line of readtext.txt separately;
# print to console and print formatted text to write.txt
lineStr = fgetline$(infile);
print(lineStr); fprint(outfile, lineStr);
lineStr = fgetline$(infile);
print(lineStr); fprintf(outfile, "%s\n", lineStr);
lineStr = fgetline$(infile);
print(lineStr); fprint(outfile, lineStr);
class STRING readtext$;
print("Now read and print the entire read.txt:");
readtext$ = TextFileReadFull(infilename$);
print(readtext$);
fclose(infile); fclose(outfile);