home *** CD-ROM | disk | FTP | other *** search
- //----------------------------------------------------------
- // WC.CPP -
- // (c) 1991 by Thole Groeneveld & toolbox -
- //----------------------------------------------------------
-
- #include <iostream.h>
- #include <iomanip.h>
- #include <fstream.h>
- #include <string.h>
- #include <ctype.h>
- #include "cstring.h"
- #include "tree.h"
-
- class StringNode : public String, public Node
- {
- public:
- StringNode (char* s) : String(s), cnt(1) { };
- int operator < (Node&);
- int operator > (Node&);
- void action();
- void equal (Node*);
- private:
- int cnt;
- };
-
- int StringNode::operator < (Node& n) {
- return *(String*)this < *(String*)(StringNode*)&n;
- }
-
- int StringNode::operator > (Node& n) {
- return *(String*)this > *(String*)(StringNode*)&n;
- }
-
- void StringNode::action() {
- cout << setw(20) << String(*this)
- << " : "
- << setw(6) << cnt << endl;
- }
-
- void StringNode::equal (Node* n) {
- cnt++;
- delete n;
- }
-
- class my_ifstream : public ifstream {
- public:
- my_ifstream();
- void open (char*);
- int getword (char*);
- private:
- char linebuf[256];
- int pos;
- int buflen;
- int DateiEOL;
- };
-
- my_ifstream::my_ifstream() {
- DateiEOL = 1;
- pos = 0;
- buflen = 0;
- }
-
- void my_ifstream::open (char *f) {
- char file[256];
- strcpy (file, f);
- ifstream::open (file);
- while ( fail() ) {
- cout << "Eingabedatei : ";
- cin >> file;
- ifstream::open (file);
- }
- }
-
- int my_ifstream::getword (char *cp) {
- do {
- if ( DateiEOL ) {
- getline (linebuf, 256);
- if ( eof() )
- return 0;
- buflen = strlen (linebuf);
- pos = 0;
- DateiEOL = 0;
- }
- while ((pos < buflen) && (!isalpha(linebuf[pos])))
- pos++;
- if ( pos >= buflen )
- DateiEOL = 1;
- }
- while ( DateiEOL );
-
- int start = pos;
- while ( isalnum(linebuf[pos]) )
- pos++;
- char sto = linebuf[pos];
- linebuf[pos] = 0;
- strcpy (cp, linebuf + start);
- linebuf[pos] = sto;
- return 1;
- }
-
-
- main (int argc, char *argv[]) {
- my_ifstream mif;
- Tree t;
- char buffer[256];
-
- mif.open ( (argc > 1) ? (argv[1]) : (0) );
- while ( mif.getword (buffer) )
- t.insert (new StringNode (buffer) );
- t.walk();
- mif.close();
- }
- //----------------------------------------------------------
- // Ende von WC.CPP -
-