/*
cxe_inputline.h
Initial Sun Mar 24 12:47:30 PST 2002
Ok, I'm tired of the C++ library struggle. I tried to find and learn
to use C++ "standard" library functions for various important things,
but it seems like there is no concept of "standard" for C++ - at least
not Linux C++. My new strategy is to create my own useful C++
programming libraries as I need them. I have resigned myself to the
fact that I will have to use purely (old) C functions to get what I
want, but I realize that I can wrap them up in functional classes that
can give the appearance of pure C++ and do exactly what I want in my
real programs.

This class will be to solve a huge glaring hole in what C++ has to
offer - input. Since the C++ stream and string libraries are
totally undocumented and unreliable on my system, I will have a class
that uses the old C functions to do important things like input file
parsing and command line parsing. 
*/

/* C++ libs as they may be found */
#include <iostream>
#include <fstream>

/* C libs as they may be needed */
#include <string.h>
#include <stdlib.h>
/* #include <stdio.h> */

class cxe_inputline
{ public:
/* Standard creator */
   cxe_inputline();
/* Creator that loads the supplied text to work with */
   cxe_inputline(char *misctext);
/* Standard destructor: */
  ~cxe_inputline();
/* Print the entire line as text */
   void print(ostream *os);
/* Checks for the presence of any supplied characters: */
   bool checkfor(char *suspects);
/* Replaces any of the supplied chars with spaces: */
   char* strip(char *bogus);
/* Replaces any characters not supplied with spaces: */
   char* stripallbut(char *goodchars);
/* Counts the number of words separated by whitespace: */
   unsigned int wordcount();
/* Read next word (indexed word) as a char array: */
   char* getnextastext(char *wordspace);
/* Read next word (indexed word) as a floating point number: */
   float getnextasfloat();
/* Read next word (indexed word) as an integer number: */
   int getnextasint();
/* Make a relative jump in the word index by n: */
//   int jumpindexby(int);

/* Needs to be protected so that extended class for files can get at
 * this stuff too. */
  protected:
   char datatext[500];
   int wordindex;
   char *wordposnow;
};

/* Define the print << operator. */
ostream &operator<<(ostream &os, cxe_inputline &P);


class cxe_finputline : public cxe_inputline
{ public:
/* Standard creator that should prepare for stdin aka cin */
   cxe_finputline();
/* Creator that opens the supplied file: */
   cxe_finputline(char *filenametxt);
/* Standard destructor */
   ~cxe_finputline();
/* Read in the next line from the file */
   char* readnextline();
/* Are we at the end of the file? */
   bool eof();
/* Is the file open? */
   bool is_open();

  private:
   ifstream *source;
};

/* Define the print << operator. */
ostream &operator<<(ostream &os, cxe_finputline &P);
