Category : Alternate Operating Systems - Quarterdeck DesqView, CP/M, etc
Archive   : PCCAPP.ZIP
Filename : TYPE1.CC

 
Output of file : TYPE1.CC contained in archive : PCCAPP.ZIP
// type1.cc: Typing tutor - you type whatever you see on the screen, and the
// program will ask you to try again if the text that you typed isn't
// the same as the text that appeared on the screen. The program stops
// when you type '#'. The text to be typed comes from the file "in.1".
#include "OutputStream.h"
#include "InputStream.h"
#include "FileSystemInterface.h"
#include "ReadFileStream.h"
#include "ReadFileStreamStar.h"
#include "WriteFileStream.h"
#include "WriteFileStreamStar.h"
#include "line.h"

int Line::ReadfromKeyboard (InputStream *in, int &end)
{
// Repeatedly read characters from "in" and write them into my line
// until a newline or ENDCHAR is read. Set "end" to true if a newline has
// been read. Return the number of characters read, not counting the
// newline. My old line is wiped out before reading any characters.
// Will not work if there are more than MAXLINE characters to be read.
length = 0;
int charsRead = in -> read (&linechar [length], 1);
while ((linechar [length] != ENDCHAR) && (charsRead > 0) &&
(linechar [length] != '\n'))
{
length++;
charsRead = in -> read (&linechar [length], 1);
}
if (linechar[length] != '\n')
end = 0;
else
end = 1;
return length;
}

int Line::ReadfromFile (ReadFileStream *in, int &end)
{
// Repeatedly read characters from "in" and write them into my line
// until a newline or ENDCHAR is read, or until there are no more
// characters to be read. Set "end" to true if a newline has
// been read. Return the number of characters read, not counting the
// newline. My old line is wiped out before reading any characters.
// Will not work if there are more than MAXLINE characters to be read.
length = 0;
int charsRead = in -> read (&linechar [length], 1);
while ((linechar [length] != ENDCHAR) && (charsRead > 0) &&
(linechar [length] != '\n'))
{
length++;
charsRead = in -> read (&linechar [length], 1);
}
if (linechar [length] != '\n')
end = 0;
else
end = 1;
return length;
}

int Line::WriteToScreen (OutputStream *out)
{
// Write my line and a newline to "out". Return the number of characters
// written, not counting the newline.
int charWritten;
if (length != 0)
{
charWritten = out -> write (linechar, length + 1); // Outputs '\n' also.
out -> flush ();
return charWritten;
}
else return 0;
}

int Line::WriteToFile (WriteFileStream *out)
{
// Write my line and a newline to "out". Return the number of characters
// written, including the newline.
if (length != 0)
return out -> write (linechar, length + 1); // Outputs '\n' also.
else
return 0;
};

int main(int, char **)
{
// This program first calls open() on StandardFileSystemInterface to open
// the file "in.1" for reading. If the call was successful, open()
// returns a ReadFileStream object (call it inf). We then read a line
// from inf, print it, repeatedly read lines from the keyboard and print
// them until we have read a line from the keyboard that matches the line
// read from inf. We keep on doing this until the user presses '#' or
// inf has run out of lines.
//
// In greater detail:
// teacherline contains the line read from inf, and studentline contains
// the line read from the keyboard. We read a line from inf into
// teacherline by calling ReadfromFile() on teacherline; we print
// teacherline by calling WriteToScreen() on teacherline; we read a line
// from the keyboard into studentline by calling ReadfromKeyboard() on
// studentline; we print studentline by calling WriteToScreen() on
// studentline; we compare studentline and teacherline by calling
// equal(). NotEnd is set to false if '#' is typed or if inf has run
// out of lines.
//
// The smart pointer ReadFileStreamStar (inf) is used here so that we don't
// have to explicitly close the file - the file will be closed
// automatically when the smart pointer goes out of scope. Standard
// FileSystemInterface (of type FileSystemInterface) is a special global
// variable used for accessing file services. StandardInput and Standard
// Output are special global variables for performing I/O to and from
// the keyboard and the screen, respectively.

int error;
// Open "in.1" for reading.
ReadFileStreamStar inf = StandardFileSystemInterface -> open
("in.1", ReadFileStreamClass, error);
if (error)
{
// Can't open "in.1", maybe because it doesn't exist. Simply give up.
*StandardOutput << "*** error opening file in.1\n" << eor;
return 0;
}

*StandardOutput << "Type a sequence of keys ending with #\n" << eor;
int NotEnd;
Line *teacherline = new Line;
Line *studentline = new Line;
// Read the first line from the file and print it for the user to type in.
teacherline -> ReadfromFile (inf, NotEnd);
teacherline -> WriteToScreen (StandardOutput);
while (NotEnd)
{
// Read what the user types in and print it to the screen. NotEnd is
// set to false if user types '#'.
studentline -> ReadfromKeyboard (StandardInput, NotEnd);
studentline -> WriteToScreen (StandardOutput);
if (NotEnd)
{
// If user didn't type '#', check whether the displayed line and the
// typed line are equal.
if (equal (studentline, teacherline))
{
// If the user typed in exactly the same line as the line displayed,
// then read another line from the file and print it. NotEnd is set
// to false if inf has run out of characters.
teacherline -> ReadfromFile (inf, NotEnd);
teacherline -> WriteToScreen (StandardOutput);
}
else
// The lines didn't match; tell the user to type again.
*StandardOutput << "Try again\n" << eor;
}
}
delete teacherline;
delete studentline;
return 0;
}


  3 Responses to “Category : Alternate Operating Systems - Quarterdeck DesqView, CP/M, etc
Archive   : PCCAPP.ZIP
Filename : TYPE1.CC

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/