//---------------------------------------------------------------------------
// тест для программ обработки текста
// 02.05.2002

#include <vcl.h>
#include <conio.h>
#pragma hdrstop
#include "ttext.h"

#pragma argsused

//TText txt, *pText;
string strs[100];  //  строки текста
int ns, nl;        // к-во строк и номер строки на экране

void TextTyper(TText &txt) { // печать текста
  clrscr(); gotoxy(1,2);
  txt.Print(); ns=0;
  for ( txt.Reset(); !txt.IsTextEnded(); txt.GoNext() )
    strs[ns++] = txt.GetLine();
  txt.GoFirstLink();
  nl=2; gotoxy(1,nl); cout << '\333'; // текущая строка
}

void TextLineMark(TText &txt) { // печать текущей строки
  string st = txt.GetLine();
  gotoxy(1,nl); cout << " ";
  for ( nl=0; nl < ns; nl++ )
    if ( st == strs[nl] ) break;
  nl+=2; gotoxy(1,nl); cout << "\333"; // текущая строка
}

#define HOME  71
#define DOWN  80
#define NEXT  77
#define UP    72
#define ESC   27
#define INS   82
#define DEL   83
#define ENTER 13

void TextProcessor(TText &txt) {
  int dir, unit;
  string st;
  char ch;
  do {
    gotoxy(1,1);
    cout << ">,v,^, Home, Ins, Del, Enter, Esc";
    ch = getch();
    if ( ch == ESC ) break;
    if ( ch != ENTER ) ch = getch();
    switch (ch) {
      case ENTER:
        gotoxy(1,1); clreol();
        cout << "Line (without blanks): "; cin >> st;
        txt.SetLine(st);
        TextTyper(txt);                break;
      case HOME: txt.GoFirstLink(); break;
      case DOWN: txt.GoDownLink();  break;
      case NEXT: txt.GoNextLink();  break;
      case UP:   txt.GoPrevLink();  break;
      case INS:
      case DEL:
        gotoxy(1,1); clreol();
        cout << "Direction: 0 - Down, 1 - Next "; cin >> dir;
        gotoxy(1,1); clreol();
        cout << "Unit: 0 - Line, 1 - Section ";   cin >> unit;
        if ( ch == INS ) { // вставка
          gotoxy(1,1); clreol();
          cout << "Line(without blanks): "; cin >> st;
          if ( dir == 0 )
            if ( unit == 0 ) txt.InsDownLine(st);
            else txt.InsDownSection(st);
          else
            if ( unit == 0 ) txt.InsNextLine(st);
            else txt.InsNextSection(st);
        }
        else { // удаление
          if ( dir == 0 )
            if ( unit == 0 ) txt.DelDownLine();
            else txt.DelDownSection();
          else
            if ( unit == 0 ) txt.DelNextLine();
            else txt.DelNextSection();
        }
        TextTyper(txt);
      break;
    }
    TextLineMark(txt);
  } while ( ch != ESC );
}

TTextMem TTextLink::MemHeader;
int main(int argc, char* argv[]) {
  TTextLink::InitMemSystem();
  TText txt, *pText;
  txt.Read("tt.dat");
  TextTyper(txt);
  TextProcessor(txt);
  cout << "Final Printing" << endl;
  TTextLink::MemCleaner(txt);
  TTextLink::PrintFreeLink();
  txt.Print();
  getch();
  cout << "printing by iterator" << endl;
  for ( txt.Reset(); !txt.IsTextEnded(); txt.GoNext() )
    cout << txt.GetLine() << endl;
//  pText = txt.GetCopy();
//  cout << "text copy" << endl;
//  pText->Print();
//  getch();
  return 0;
}
//---------------------------------------------------------------------------
Хостинг от uCoz