delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/06/11/06:01:28

Xref: news2.mv.net comp.os.msdos.djgpp:4832
From: boylesgj AT lion DOT cs DOT latrobe DOT edu DOT au (Gregary J Boyles)
Newsgroups: comp.os.msdos.djgpp
Subject: Compiler error????
Date: 11 Jun 1996 07:03:32 GMT
Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
Lines: 2051
Distribution: world
Message-ID: <4pj5o4$pfp@lion.cs.latrobe.edu.au>
NNTP-Posting-Host: lion.cs.latrobe.edu.au
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Newsgroups: comp.os.msdos.djgpp
Subject: Compiler errors????????
Summary: 
Followup-To: 
Distribution: world
Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
Keywords: 

What does this crap mean???
I'm not making calls to clear!
See files included below - sorry I can't remove irrelavent code 
because I haven't clue what all this means or what might be causing it.

In file included from /usr/local/lib/g++-include/iostream.h:31,
                 from stringc.hpp:10,
                 from field.cpp:5:
/usr/local/lib/g++-include/streambuf.h:207: arguments given to macro `clear'
In file included from stringc.hpp:10,
                 from field.cpp:5:
/usr/local/lib/g++-include/iostream.h:169: arguments given to macro `clear'
/usr/local/lib/g++-include/iostream.h:172: arguments given to macro `clear'

/*

   File field.hpp

   Class specifications

*/

#ifndef __FIELD_HPP
#define __FIELD_HPP




/*
*****************************************************************************
*                                                                           *
* ENUMERATED TYPE NAME : CommandTypeE                                       *
*                                                                           *
* PURPOSE : To seperate key scan codes from invocation of system modules in *
*           order  to make changing the keys used, by the system, easier.   *
*                                                                           *
* NOTE : When a key is pressed the Read modules get the character(s) from   *
*        the key board buffer, determine whether they belong to a command   *
*        key e.g. up arrow or esc and if so return the corresponding system *
*        command.                                                           *
*        MB stands for menu bar.                                            *
*                                                                           *
*****************************************************************************
*/
typedef enum {Next,Cancel,Enter,Tag,Untag,Print,Up,Down,Left,Right,PageUp,
              PageDown,EndLine,StartLine,Insert,Delete,None,Error,Add1,Add10,
              Add100,Add1000,Subtract1,Subtract10,Subtract100,Subtract1000,
              
              SearchA,SearchB,SearchD,SearchE,SearchF,SearchG,SearchH,SearchI,
              SearchJ,SearchK,SearchL,SearchM,SearchN,SearchO,SearchP,SearchQ,
              SearchR,SearchS,SearchT,SearchU,SearchV,SearchW,SearchX,SearchY,
              SearchZ,Search0,Search1,Search2,Search3,Search4,Search5,Search6,
              Search7,Search8,Search9,

              MBFile,MBEntry,MBView,MBPrint,MBHelp,

              MBFileUsers,MBFileAnalysis,MBFileColors,MBFileLogout,MBFileQuit,

              MBEntryInvoices,MBEntryOrders,MBEntryProducts,MBEntryCustomers,

              MBViewInvoices,MBViewOrders,MBViewProducts,MBViewCustomers,MBViewSuppliers,

              MBPrintInvoices,MBPrintOrders,MBPrintProducts,MBPrintCustomers,
              MBPrintSuppliers,

              MBHelpContents,MBHelpIndex,MBHelpAbout} CommandTypeE;




/*
*****************************************************************************
*                                                                           *
* CLASS NAME : PositionC                                                    *
*                                                                           *
* PURPOSE : To store coordinates of a single position.                      *
*                                                                           *
* NOTE :                                                                    *
*                                                                           *
*****************************************************************************
*/
class PositionC
{
  private :
    // Position coordinates.
    int X,Y;

  public :
    // The constructors.
    PositionC();

    PositionC(const int X_,const int Y_);

    // The destructor.
    ~PositionC();

    // Functions for setting and getting data members.
    void SetPosition(const int X_,const int Y_);

    int GetX();
    int GetY();
};




/*
*****************************************************************************
*                                                                           *
* CLASS NAME : FieldC                                                       *
*                                                                           *
* PURPOSE : To store details of a field in a dialog box, corresponding to   *
*           field in a database record.                                     *
*                                                                           *
* NOTE :                                                                    *
*                                                                           *
*****************************************************************************
*/
class FieldC
{
  private:
    // The name of the field.
    StringC Name;

    // The position of the field in the dialog box.
    PositionC Position;

    // The length of the data field in the field.
    int FieldLength;

    // Data members to store the field's data.
    StringC String;

    int Integer;

    char Ch;

   public:
    // The constructors.
    FieldC();

    FieldC(const char *Name_,const int X_,const int Y_,const int FieldLength_,const char *String_);

    FieldC(const char *Name_,const int X_,const int Y_,const int FieldLength_,const int Integer_);

    FieldC(const char *Name_,const int X_,const int Y_,const int FieldLength_,const char Ch_);

    FieldC(const char *Name_,const int X_,const int Y_,const int FieldLength_);

    // The destructor.
    ~FieldC();

    // Functions for getting and setting individual data members.
    void SetName(const char *Name_);

    const StringC &GetName();

    void SetPosition(const int X_,const int Y_);

    void GetPosition(int &X_,int &Y_);

    void SetFieldLength(const int FieldLength_);

    int GetFieldLength();

    void SetString(const char *String_);

    const char *GetString();

    void SetInteger(const int Integer_);

    int GetInteger();

    // Display function.
    void Display(WINDOW *Win);

    // Input functions.
    CommandTypeE ReadInteger(WINDOW *Win,const int Upper,const int Lower);

    CommandTypeE ReadString(WINDOW *Win);

    CommandTypeE ReadChar(WINDOW *Win);

    CommandTypeE ChangeInteger(WINDOW *Win,const int Upper,const int Lower);

    CommandTypeE ReadCommand(WINDOW *Win);
};




#endif



/*

   File field.cpp

   Class implementations

*/
#include <curses.h>
#include <stdio.h>
#include <stdlib.h>
#include "string.hpp"
#include "display.hpp"
#include "keycodes.hpp"




/*
*****************************************************************************
*                                                                           *
* CLASS PositionC                                                           *
*                                                                           *
*****************************************************************************
*/

// The constructors.
PositionC::PositionC()
{
  X=0;
  Y=0;
}




PositionC::PositionC(const int X_,const int Y_)
{
  X=X_;
  Y=Y_;
}




// The destructor.
PositionC::~PositionC()
{
  X=0;
  Y=0;
}




// Functions for setting and getting data members.
void PositionC::SetPosition(const int X_,const int Y_)
{
  X=X_;
  Y=Y_;
}




int PositionC::GetX()
{
  return X;
}




int PositionC::GetY()
{
  return Y;
}




/*
*****************************************************************************
*                                                                           *
* CLASS NAME : FieldC                                                       *
*                                                                           *
*****************************************************************************
*/

// The constructors.
FieldC::FieldC():

Name(),Position(),String()

{
  FieldLength=0;
  Integer=0;
  Ch=Null;
}




FieldC::FieldC(const char *Name_,const int X_,const int Y_,
               const int FieldLength_,const char *String_):

Name(Name_),String(String_),Position(X_,Y_)

{
  FieldLength=FieldLength_;
  Integer=0;
  Ch=Null;
}




FieldC::FieldC(const char *Name_,const int X_,const int Y_,
               const int FieldLength_,const int Integer_):

Name(Name_),String(),Position(X_,Y_)

{
  FieldLength=FieldLength_;
  Integer=Integer_;
  Ch=Null;
}





FieldC::FieldC(const char *Name_,const int X_,const int Y_,
               const int FieldLength_,const char Ch_):

Name(Name_),Position(X_,Y_),String()

{
  FieldLength=FieldLength_;
  Integer=Integer_;
  Ch=Ch_;
}


FieldC::FieldC(const char *Name_,const int X_,const int Y_,
               const int FieldLength_):

Name(Name_),Position(X_,Y_),String()

{
  FieldLength=FieldLength_;
  Integer=Integer_;
  Ch=Null;
}




// The destructor.
FieldC::~FieldC()
{
  FieldLength=0;
  Integer=0;
  Ch=Null;
}





// Functions for getting and setting individual data members.
void FieldC::SetName(const char *Name_)
{
  Name=Name_;
}




const StringC &FieldC::GetName()
{
  return Name;
}





void FieldC::SetPosition(const int X_,const int Y_)
{
  Position.SetPosition(X_,Y_);
}




void FieldC::GetPosition(int &X_,int &Y_)
{
  X_=Position.GetX();
  Y_=Position.GetY();
}




void FieldC::SetFieldLength(const int FieldLength_)
{
  FieldLength=FieldLength_;
}




int FieldC::GetFieldLength()
{
  return FieldLength;
}




void FieldC::SetString(const char *String_)
{
  String=String_;
}




const char *FieldC::GetString()
{
  return String.GetS();
}




void FieldC::SetInteger(const int Integer_)
{
  Integer=Integer_;
}




int FieldC::GetInteger()
{
  return Integer;
}




// Display function.
void FieldC::Display(WINDOW *Win)
{
  int Index;

  Name.MvWAddStr(Win,Position.GetY(),Position.GetX(),1,Name.Length());
  waddch(Win,'[');
  String.WAddStr(Win,1,FieldLength);
  for (Index=String.Length()+1;Index<=FieldLength;Index++)
    waddch(Win,' ');
  waddch(Win,']');
}




// Input functions.
CommandTypeE FieldC::ReadCommand(WINDOW *Win)
{
  int Ch1=NULL,Ch2=Null;
  CommandTypeE Command;

  do
  {
    Ch1=wgetch(Win);
    if (Ch1==Null)
      Ch2=wgetch(Win);
    else
      Ch2=NULL;

    if (Ch1==Tab)
      Command=Next;
    else if (Ch1==Escape)
      Command=Cancel;
    else if (Ch1==CarriageReturn)
      Command=Enter;
    else if (Ch2==UpArrow)
      Command=Add1;
    else if (Ch2==DownArrow)
      Command=Subtract1;
    else if (Ch2==PgUp)
      Command=Add10;
    else if (Ch2==PgDn)
      Command=Subtract10;
    else if (Ch1==ShiftPgUp)
      Command=Add100;
    else if (Ch1==ShiftPgDn)
      Command=Subtract100;
    else if (Ch2==CtrlPgUp)
      Command=Add1000;
    else if (Ch2==CtrlPgDn)
      Command=Subtract1000;
    else
      Command=None;
  }
  while (Command!=None);

  return Command;
}




CommandTypeE FieldC::ReadChar(WINDOW *Win)
{
  char Ch1=Null,Ch2=Null;
  CommandTypeE Command;
  bool Done,CharPressed=false;

  do
  {
    Ch1=wgetch(Win);
    if (Ch1==Null)
      Ch2=wgetch(Win);
    else
      Ch2=Null;

    if ((Ch1==BackSpace) || (Ch2==Del))
    {
      Command=Delete;
      Done=true;
      CharPressed=false;
    }
    else if (Ch1==Tab)
    {
      Command=Next;
      Done=true;
    }
    else if (Ch1==Escape)
    {
      Command=Cancel;
      Done=true;
    }
    else if (Ch1==CarriageReturn)
    {
      Command=Enter;
      Done=true;
    }
    else if ((Ch1>=Space) && (Ch1<=Tilde) && (!CharPressed))
    {
      Command=None;
      Ch=Ch1;
    }
  }
  while (!Done);

  return Command;
}




CommandTypeE FieldC::ReadInteger(WINDOW *Win,const int Lower,const int Upper)
{
  int X=Position.GetX()+Name.Length()+1,Y=Position.GetY(),TempInteger,Index;
  StringC TempString;
  CommandTypeE Command;

  TempString="";
  wmove(Win,Y,X);
  do
  {
    Command=ReadChar(Win);

    // If the delete command was issued and the length of string is greater
    // than 0.
    if ((Command==Delete) && (String.Length()>0))
    {
      // Decrement the x coordinate : X.
      X--;

      // Remove the last character from TempString.
      TempString-=TempString[TempString.Length()];

      // Erase the last character from the screen.
      mvwaddch(Win,Y,X,Space);
      wmove(Win,Y,X);
      wrefresh(Win);
    }
    // If the enter command was issued.
    else if (Command==Enter)
    {
      // If TempString could not be converted to an integer or the integer is
      // out of the prescribed range then reset TempString to "" and clear the
      // field and start again.
      if (!TempString.ToInt(TempInteger) || (TempInteger<Lower) || (TempInteger>Upper))
      {
        // Change the value of command so that the loop does not terminate.
        Command=None;

        // Set X back to its original value.
        X=Position.GetX()+Name.Length()+1;

        // Empty TempString.
        TempString="";

        // Erase the field.
        wmove(Win,X,Y);
        for (Index=1;Index<=FieldLength;Index++)
          waddch(Win,Space);
        wmove(Win,X,Y);
        wrefresh(Win);
      }
      // If no errors then assign the Temp variables into the field data
      // members.
      else
      {
        String=TempString;
        Integer=TempInteger;
      }
    }
    // If a digit key was pressed and the length of TempString is less than
    // the length of the field.
    else if ((Ch>=Digit0) && (Ch<=Digit9) && (TempString.Length()<FieldLength))
    {
      // Echo the character.
      mvwaddch(Win,Y,X,Ch);
      wrefresh(Win);

      // Add it to String.
      TempString+=Ch;

      // Increment the x coordinate : X.
      X++;
    }
  }
  while ((Command!=Enter) && (Command!=Cancel) && (Command!=Next));

  return Command;
}




CommandTypeE FieldC::ReadString(WINDOW *Win)
{
  int X=Position.GetX()+Name.Length()+1,Y=Position.GetY();
  CommandTypeE Command;

  String="";
  wmove(Win,Y,X);
  do
  {
    Command=ReadChar(Win);

    // If the delete command was issued and the length of string is greater
    // than 0.
    if ((Command==Delete) && (String.Length()>0))
    {
      // Decrement the x coordinate : X.
      X--;

      // Remove the last character from String.
      String-=String[String.Length()];

      // Erase the last character from the screen.
      mvwaddch(Win,Y,X,Space);
      wmove(Win,Y,X);
      wrefresh(Win);
    }
    // If a digit, alphabetic or punctuation key was pressed and the length of
    // String is less than the length of the field.
    else if ((Ch>=Space) && (Ch<=Tilde) && (String.Length()<FieldLength))
    {
      // Echo the character.
      mvwaddch(Win,Y,X,Ch);
      wrefresh(Win);

      // Add it to String.
      String+=Ch;

      // Increment the x coordinate : X.
      X++;
    }
  }
  while ((Command!=Enter) && (Command!=Cancel) && (Command!=Next));

  return Command;
}




CommandTypeE FieldC::ChangeInteger(WINDOW *Win,const int Upper,const int Lower)
{
  CommandTypeE Command;
  int TempInt;

  do
  {
    Command=ReadCommand(Win);

    if (Command==Add1)
    {
      TempInt++;
    }
    else if (Command==Subtract1)
    {
      TempInt--;
    }
    else if (Command==Add10)
    {
      TempInt+=10;
    }
    else if (Command==Subtract10)
    {
      TempInt-=10;
    }
    else if (Command==Add100)
    {
      TempInt+=100;
    }
    else if (Command==Subtract100)
    {
      TempInt-=100;
    }
    else if (Command==Add1000)
    {
      TempInt+=1000;
    }
    else if (Command==Subtract1000)
    {
      TempInt-=1000;
    }
    // TempInt is within the specified range.
    if ((TempInt>=Lower) && (TempInt<=Upper))
    {
      // Convert Integer to a string.
      String=TempInt;

      // If the TempInt fits within the field.
      if (String.Length()<=FieldLength)
      {
        Integer=TempInt;

        // Display String.
        String.MvWAddStr(Win,Position.GetY(),Position.GetX(),1,FieldLength);
        wrefresh(Win);
      }
      // Otherwise set String to its original value.
      else
        String=Integer;
    }
  }
  while ((Command!=Enter) && (Command!=Cancel) && (Command!=Next));

  return Command;
}




/*
   File string.hpp

   StringC class specification.
*/

#ifndef __STRING_HPP
#define __STRING_HPP

#include <iostream.h>
#include <fstream.h>
#include <curses.h>

/*
*****************************************************************************
*                                                                           *
* CLASS NAME : StringC                                                      *
*                                                                           *
* PURPOSE : To provide Pascal like string manipulations.                    *
*                                                                           *
* NOTE : Statements such as String1=String2, String1="hello",               *
*        String1+="there, String1+=String2, String1-="there",               *
*        String1-=String2, String3=String1+String2, String3=String1-String2,*
*        String1[2]='c', String1=="hello", String1==String2, cout<<String1  *
*        and cin>>String1 are posible with this class.                      *
*        In addition to these there are many more useful functions and in   *
*        fact there is no need to use string.h at all.                      *
*                                                                           *
*****************************************************************************
*/
class StringC
{
  private : 
    // Data members
    int L; // AString length;
    char *S; // The string

  public : 
    // Constructors
    StringC(const char *AString);
    StringC(const StringC &AString);
    StringC();

    // Destructor
    ~StringC();

    // Friend functions
    friend ofstream &operator <<(ofstream &OFS,const StringC &AString);
    friend ifstream &operator >>(ifstream &IFS,StringC &AString);
    friend ostream &operator <<(ostream &OS,const StringC &AString);
    friend istream &operator >>(istream &IS,StringC &AString);

    // Operator function members
    void operator -=(const char *AString); // Substring deletion
    StringC &operator -(const char *AString); // Substring deletion
    void operator +=(const char *AString); // String concatenation
    StringC &operator +(const char *AString); // String concatenation
    void operator =(const char *AString); // String assignment
    bool  operator ==(const char *AString); // Case insensitive equal
    bool  operator >(const char *AString); // Case insensitive greater
    bool  operator <(const char *AString); // Case insensitive less
    bool  operator !=(const char *AString); // Case insensitive not equal
    int operator *(const char *AString); // Sub-string search

    void operator -=(const StringC &AString); // Substring deletion
    StringC &operator -(const StringC &AString); // Substring deletion
    void operator +=(const StringC &AString); //String concatenation
    StringC &operator +(const StringC &AString); // String concatenation
    void operator =(const StringC &AString); // String assignment
    bool  operator ==(const StringC &AString); // Case insensitive equal
    bool  operator >(const StringC &AString); // Case insensitive greater
    bool  operator <(const StringC &AString); // Case insensitive less
    bool  operator !=(const StringC &AString); // Case insensitive not equal
    int operator *(const StringC &AString); // Substring search

    void operator -=(const char Ch); // Character deletion
    StringC &operator -(const char Ch); // Character deletion
    void operator +=(const char Ch); // Character concatenation
    StringC &operator +(const char Ch); // Character concatenation
    int operator *(char Ch); // Character search
    char &operator [](int Pos); //String sub-scripting

    // Integer to string conversion.
    void operator =(int Integer);

    // Other function members
    int Length(); // Return the length of the string
    void Delete(int Pos,int Num); // Delete Num characters from position Pos
    void Insert(const StringC &AString,int PosToAdd); // Insert AString at position PosToAdd
    void Insert(const char *AString,int PosToAdd); // Insert AString at position PosToAdd
    bool Equal(const StringC &AString); // Case sensitive comparisons
    bool NotEqual(const StringC &AString);
    bool Greater(const StringC &AString);
    bool Less(const StringC &AString);
    bool Equal(const char *AString); // Case sensitive comparisons
    bool NotEqual(const char *AString);
    bool Greater(const char *AString);
    bool Less(const char *AString);
    void Set(const char Ch); // Set all characters to Ch
    const char *GetS(); // Returns (char *) S.
    bool ToInt(int &Integer);

    // These functions provide compatibility between StringC objects and
    // curses string input and output.
    void MvWAddStr(WINDOW *Win,const int Y,const int X,const int Position,const int Length);
    void WAddStr(WINDOW *Win,const int Position,const int Length);
};



#endif



/*

   File string.cpp

   StringC class implementation
*/
#include <string.h>
#include <iostream.h>
#include <fstream.h>
#include <stdio.h>
#include <math.h>
#include "string.hpp"




// LOCAL CONSTANTS

const char EOLN='\n';
const char EOS='\0';
const char SPACE=' ';
const int MAXSTRING=100;


/*
   Local string variable for temporarily storing strings.

   All string operations are performed using TempString1 and when they are complete
   S is deleted, an appropriate amount of memory is re-allocated and the contents
   of TempString1 are copied into S. In this way S always has the minumum amount
   of memory required.

   Before using TempString1, all its elements are set to '\0' by the call
   strset(S,EOS). This guarentees that S will contain the expected string value
stream
   when using the Borland Tubo C++ string functions. These 
functions do not always
   append a '\0' to the end of a string.
   E.G. If TempString1 contains "Hello there" and we replace it with the value
   "bye", using the various string functions, then, in some cases, TempString1
   will end up containing the value "byelo there" because a '\0' was not
   appended to "bye"
*/

char TempString1[MAXSTRING];
char TempString2[MAXSTRING];




/*
   Local StringC object for temporarily storing strings created by the
   operator functions + and -
*/

StringC TempString_;




// LOCAL UTILITY FUNCTIONS.

void strset_(char *AString,char Ch,int Length)
// Set all elements of AString to Ch.
{
  int Index;

  for(Index=0;Index<Length;Index++)
    AString[Index]=Ch;
}




char Char(int Number)
{
  typedef union{int IntValue;char CharValue;} ConverterType;
  ConverterType Converter;

  Converter.IntValue=Number;
  return Converter.CharValue;
}




// CONSTRUCTORS

StringC::StringC(const char *AString)
{
  delete S;
  L=strlen(AString);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,AString);
}




StringC::StringC(const StringC &AString)
{
  delete S;
  L=strlen(AString.S);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,AString.S);
}




StringC::StringC()
{
  L=0;
  S=new char[L+2];
  strset_(S,EOS,L+2);
}




// DESTRUCTOR

StringC::~StringC()
{
  delete S;
  S=NULL;
  L=0;
}




// FRIEND FUNCTIONS

ofstream &operator <<(ofstream &OFS,const StringC &AString)
// StringC file output
{

  OFS<<(AString.S);
  return OFS;
}



 
ifstream &operator >>(ifstream &IFS,StringC &AString)
// StringC file input
{
  strset_(TempString1,EOS,MAXSTRING);
  IFS.getline(TempString1,MAXSTRING,EOLN);

  AString.L=strlen(TempString1);
  delete AString.S;
  AString.S=new char[AString.L+1];
  strset_(AString.S,EOS,AString.L+1);
  strcpy(AString.S,TempString1);
  return IFS;
}




ostream &operator <<(ostream &OS,const StringC &AString)
// StringC output
{
  OS<<AString.S;
  return OS;
}




istream &operator >>(istream &IS,StringC &AString)
{
  strset_(TempString1,EOS,MAXSTRING);
  IS.getline(TempString1,MAXSTRING,EOLN);

  AString.L=strlen(TempString1);
  delete AString.S;
  AString.S=new char[AString.L+1];
  strset_(AString.S,EOS,AString.L+1);
  strcpy(AString.S,TempString1);
  return IS;
}




// MEMBER FUNCTIONS
void StringC::MvWAddStr(WINDOW *Win,const int Y,const int X,const int Position,const int Length)
// Curses string output.
{
  char *SubString;

  // TempString1 is filled with spaces and then Length or less characters of
  // S is copied to TempString1 (char *).
  strset_(TempString1,SPACE,MAXSTRING);
  SubString=S+Position-1;
  strncpy(TempString1,SubString,Length);
  // Add the string terminator to position Length.
  TempString1[Length]=EOS;
  mvwaddstr(Win,Y,X,TempString1);
}



void StringC::WAddStr(WINDOW *Win,const int Position,const int Length)
// Curses string output.
{
  char *SubString;

  // TempString1 is filled with spaces and then Length or less characters of
  // S is copied to TempString1 (char *).
  strset_(TempString1,SPACE,MAXSTRING);
  SubString=S+Position-1;
  strncpy(TempString1,SubString,Length);
  // Add the string terminator to position Length.
  TempString1[Length]=EOS;
  waddstr(Win,TempString1);
}



void StringC::operator -=(const char *AString)
// If S contains the sub-string AString then delete it and return the resulting
// string.
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  // Search for AString in S and store the pointer in SubString
  SubString=strstr(S,AString);
  // If S does not contain AString then simply copy S to TempString1
  if (SubString==NULL)
  {
    strcpy(TempString1,S);
  }
  else
  {
    // Calculate the number of characters between the start of S and the start
    // of AString in S (SubString)
    NumToCopy=abs(S-SubString);
    // Copy NumToCopy characters from S to TempString1
    strncpy(TempString1,S,NumToCopy);
    // If AString is smaller than the remainder of S
    if (strlen(AString)<(L-NumToCopy))
    {
      // Move SubString to the end of AString in S
      SubString+=strlen(AString);
      // Concatenate the remaining characters of S to TempString1
      strcat(TempString1,SubString);
    }
  }

  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,TempString1);
}




StringC &StringC::operator -(const char *AString)
// If S contains the sub-string AString then delete it and return the resulting
// string.
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  // Search for AString in S and store the pointer in SubString
  SubString=strstr(S,AString);
  // If S does not contain AString.S then simply copy S to TempString_.S
  if (SubString==NULL)
  {
    strcpy(TempString1,S);
  }
  else
  {
    // Calculate the number of characters between the start of S and the start
    // of AString in S (SubString)
    NumToCopy=abs(S-SubString);
    // Copy NumToCopy characters from S to TempString1
    strncpy(TempString1,S,NumToCopy);
    // If AString is smaller than the remainder of S
    if (strlen(AString)<(L-NumToCopy))
    {
      // Move SubString to the end of AString.S in S
      SubString+=strlen(AString);
      // Concatenate the remaining characters of S to TempString_.S
      strcat(TempString1,SubString);
    }
  }
  delete TempString_.S;
  TempString_.L=strlen(TempString1);
  TempString_.S=new char[TempString_.L+1];
  strset_(TempString_.S,EOS,TempString_.L+1);
  strcpy(TempString_.S,TempString1);
  return TempString_;
}




void StringC::operator +=(const char *AString)
// Concatenate S and AString and assign the resulting string into S
{
  strset_(TempString1,EOS,MAXSTRING);
  strcpy(TempString1,S);
  strcat(TempString1,AString);

  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,TempString1);
}




StringC &StringC::operator +(const char *AString)
// Concatenate S and AString and return the resulting string
{
  strset_(TempString1,EOS,MAXSTRING);
  strcpy(TempString1,S);
  strcat(TempString1,AString);
  delete TempString_.S;
  TempString_.L=strlen(TempString1);
  TempString_.S=new char[TempString_.L+1];
  strset_(TempString_.S,EOS,TempString_.L+1);
  strcpy(TempString_.S,TempString1);
  return TempString_;
}




void StringC::operator =(const char *AString)
// StringC/char * assignment
{
  delete S;
  L=strlen(AString);
  S=new char[L+1];
  strset_(S,EOS,L);
  strcpy(S,AString);
}




bool StringC::operator ==(const char *AString)
// StringC input
{
  bool Result;
  int Num;

  Num=strcasecmp(S,AString);
  if (Num==0)
    Result=true;
  else
    Result=false;
  return Result;
}




bool StringC::operator >(const char *AString)
// Case insensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcasecmp(S,AString);
  if (Num>0)
    Result=true;
  else
    Result=false;
  return Result;
}




bool StringC::operator <(const char *AString)
// Case insensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcasecmp(S,AString);
  if (Num<0)
    Result=true;
  else
    Result=false;
  return Result;
}




bool StringC::operator !=(const char *AString)
// Case insensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcasecmp(S,AString);
  if (Num!=0)
    Result=true;
  else
    Result=false;
  return Result;
}




int StringC::operator *(const char *AString)
// If S contains the sub-string AString then return the start position or else
// return 0
{
  char *SubString;
  int Result;

  SubString=strstr(S,AString);

  if (SubString!=NULL)
    Result=abs(S-SubString)+1;
  else
    Result=NULL;

  return Result;
}




void StringC::operator -=(const StringC &AString)
// If S contains the sub-string AString.S then delete it and assign the resulting
// string into S
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  // Search for AString.S in S and store the pointer in SubString
  SubString=strstr(S,AString.S);
  // If S does not contain AString.S then simply copy S to TempString1
  if (SubString==NULL)
  {
    strcpy(TempString1,S);
  }
  else
  {
    // Calculate the number of characters between the start of S and the start
    // of AString.S in S (SubString)
    NumToCopy=abs(S-SubString);
    // Copy NumToCopy characters from S to TempString1
    strncpy(TempString1,S,NumToCopy);
    // If AString.S is smaller than the remainder of S
    if (strlen(AString.S)<(L-NumToCopy))
    {
      // Move SubString to the end of AString.S in S
      SubString+=AString.L;
      // Concatenate the remaining characters of S to TempString1
      strcat(TempString1,SubString);
    }
  }

  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,TempString1);
}




StringC &StringC::operator -(const StringC &AString)
// If S contains the sub-string AString.S then delete it and return the resulting
// string.
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  // Search for AString.S in S and store the pointer in SubString
  SubString=strstr(S,AString.S);
  // If S does not contain AString.S then simply copy S to TempString1
  if (SubString==NULL)
  {
    strcpy(TempString1,S);
  }
  else
  {
    // Calculate the number of characters between the start of S and the start
    // of AString.S in S (SubString)
    NumToCopy=abs(S-SubString);
    // Copy NumToCopy characters from S to TempString1
    strncpy(TempString1,S,NumToCopy);
    // If AString.S is smaller than the remainder of S
    if (strlen(AString.S)<(L-NumToCopy))
    {
      // Move SubString to the end of AString.S in S
      SubString+=AString.L;
      // Concatenate the remaining characters of S to TempString1
      strcat(TempString1,SubString);
    }
  }
  delete TempString_.S;
  TempString_.L=strlen(TempString1);
  TempString_.S=new char[TempString_.L+1];
  strset_(TempString_.S,EOS,TempString_.L+1);
  strcpy(TempString_.S,TempString1);
  return TempString_;
}




void StringC::operator +=(const StringC &AString)
// Concatenate S and AString.S and assign return the resulting string.
{
  strset_(TempString1,EOS,MAXSTRING);
  strcpy(TempString1,S);
  strcat(TempString1,AString.S);

  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,TempString1);
}




StringC &StringC::operator +(const StringC &AString)
// Concatenate S and AString.S and return the resulting string
{
  strset_(TempString1,EOS,MAXSTRING);
  strcpy(TempString1,S);
  strcat(TempString1,AString.S);
  delete TempString_.S;
  TempString_.L=strlen(TempString1);
  TempString_.S=new char[TempString_.L+1];
  strset_(TempString_.S,EOS,TempString_.L+1);
  strcpy(TempString_.S,TempString1);
  return TempString_;
}




void StringC::operator =(const StringC &AString)
// StringC/StringC assignment
{
  delete S;
  L=AString.L;
  S=new char[L+1];
  strset_(S,EOS,L);
  strcpy(S,AString.S);
}




int StringC::operator *(const StringC &AString)
// If S contains the sub-string AString.S then return the start position or else
// return 0
{
  char *SubString;
  int Result;

  SubString=strstr(S,AString.S);

  if (SubString!=NULL)
    Result=abs(S-SubString)+1;
  else
    Result=NULL;

  return Result;
}




bool StringC::operator ==(const StringC &AString)
// StringC input
{
  bool Result;
  int Num;

  Num=strcasecmp(S,AString.S);
  if (Num==0)
    Result=true;
  else
    Result=false;
  return Result;
}




bool StringC::operator >(const StringC &AString)
// Case insensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcasecmp(S,AString.S);
  if (Num>0)
    Result=true;
  else
    Result=false;
  return Result;
}




bool StringC::operator <(const StringC &AString)
// Case insensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcasecmp(S,AString.S);
  if (Num<0)
    Result=true;
  else
    Result=false;
  return Result;
}




bool StringC::operator !=(const StringC &AString)
// Case insensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcasecmp(S,AString.S);
  if (Num!=0)
    Result=true;
  else
    Result=false;
  return Result;
}




void StringC::operator -=(const char Ch)
// If S contains the character Ch then delete it and return the resulting string.
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  // Convert Ch to a (char *) string.
  strset_(TempString2,EOS,MAXSTRING);
  TempString2[0]=Ch;
  // Search for TempString2 (Ch) in S and store the pointer in SubString
  SubString=strstr(S,TempString2);
  // If S does not contain AString then simply copy S to TempString1
  if (SubString==NULL)
  {
    strcpy(TempString1,S);
  }
  else
  {
    // Calculate the number of characters between the start of S and the start
    // of AString in S (SubString)
    NumToCopy=abs(S-SubString);
    // Copy NumToCopy characters from S to TempString1
    strncpy(TempString1,S,NumToCopy);
    // Move SubString on by one character.
    SubString+=1;
    // Concatenate the remaining characters of S to TempString1 if any.
    strcat(TempString1,SubString);
  }

  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,TempString1);
}




StringC &StringC::operator -(const char Ch)
// If S contains the character Ch then delete it and return the resulting string.
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  // Convert Ch to a string.
  strset_(TempString2,EOS,MAXSTRING);
  TempString2[0]=Ch;
  // Search for TempString2 (Ch) in S and store the pointer in SubString
  SubString=strstr(S,TempString2);
  // If S does not contain TempString1 (Ch) then simply copy S to TempString_.S
  if (SubString==NULL)
  {
    strcpy(TempString1,S);
  }
  else
  {
    // Calculate the number of characters between the start of S and the start
    // of AString in S (SubString)
    NumToCopy=abs(S-SubString);
    // Copy NumToCopy characters from S to TempString1
    strncpy(TempString1,S,NumToCopy);
    // Move SubString on one character.
    SubString+=1;
    // Concatenate the remaining characters of S to TempString_.S if any.
    strcat(TempString1,SubString);
  }
  delete TempString_.S;
  TempString_.L=strlen(TempString1);
  TempString_.S=new char[TempString_.L+1];
  strset_(TempString_.S,EOS,TempString_.L+1);
  strcpy(TempString_.S,TempString1);
  return TempString_;
}




void StringC::operator +=(const char Ch)
// Concatenate S and Ch and assign return the resulting string.
{
  strset_(TempString1,EOS,MAXSTRING);
  strcpy(TempString1,S);
  TempString1[strlen(TempString1)]=Ch;

  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,TempString1);
}




StringC &StringC::operator +(const char Ch)
// Concatenate S and Ch and return the resulting string
{
  strset_(TempString1,EOS,MAXSTRING);
  strcpy(TempString1,S);
  TempString1[strlen(TempString1)]=Ch;
  delete TempString_.S;
  TempString_.L=strlen(TempString1);
  TempString_.S=new char[TempString_.L+1];
  strset_(TempString_.S,EOS,TempString_.L+1);
  strcpy(TempString_.S,TempString1);
  return TempString_;
}




int StringC::operator *(char Ch)
// If S contains the character Ch then return its position or else return 0
{
  char *SubString;
  int Result;

  SubString=strchr(S,Ch);

  if (SubString!=NULL)
    Result=abs(S-SubString)+1;
  else
    Result=NULL;

  return Result;
}




char &StringC::operator [](int Pos)
// StringC sub-scripting
{
  if (!((Pos<=L) && (Pos>0)))
  {
    cout<<"ERROR : string subscript is out of range . . ."<<EOLN<<EOLN;
    exit(1);
  }
  return S[Pos-1];
}




void StringC::operator =(int Integer)
// Converts Integer to a string.
{
  strset_(TempString1,EOS,MAXSTRING);
  sprintf(TempString1,"%d",Integer);
  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,TempString1);
 }



int StringC::Length()
// Return the length of S (L)
{
  return L;
}




void StringC::Delete(int PosToDeleteFrom,int NumToDelete)
// Delete NumToDelete characters from S starting at PosToDeletFrom
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  // PosToDelete is greater the the length of S then just copy S to TempString1
  if (PosToDeleteFrom>L)
  {
    strcpy(TempString1,S);
  }
  // If PosToDeleteFrom is 1 and NumToDelete is equal to or larger than the
  // length of S then simply copy a null string to TempString1
  else if ((PosToDeleteFrom==1) && (NumToDelete>=L))
  {
    strcpy(TempString1,"");
  }
  else
  {
    // If there is less than NumToDelete characters between PosToDeleteFrom
    // and the end of S then adjust the value of NumToDelete
    if ((NumToDelete+PosToDeleteFrom-1)>L)
      NumToDelete=L-PosToDeleteFrom+1;

    SubString=S+PosToDeleteFrom-1;
    NumToCopy=abs(S-SubString);
    strncpy(TempString1,S,NumToCopy);
    SubString+=NumToDelete;
    strcat(TempString1,SubString);
  }

  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L+1);
  strcpy(S,TempString1);
}




void StringC::Insert(const StringC &AString,int Pos)
// Insert AString.S into S before position Pos
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  SubString=S+Pos-1;
  NumToCopy=abs(S-SubString);
  strncpy(TempString1,S,NumToCopy);
  strcat(TempString1,AString.S);
  strcat(TempString1,SubString);
  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L);
  strcpy(S,TempString1);
}




void StringC::Insert(const char *AString,int Pos)
// Insert AString into S before position Pos
{
  char *SubString;
  int NumToCopy;

  strset_(TempString1,EOS,MAXSTRING);
  SubString=S+Pos-1;
  NumToCopy=abs(S-SubString);
  strncpy(TempString1,S,NumToCopy);
  strcat(TempString1,AString);
  strcat(TempString1,SubString);
  delete S;
  L=strlen(TempString1);
  S=new char[L+1];
  strset_(S,EOS,L);
  strcpy(S,TempString1);
}




bool StringC::Equal(const StringC &AString)
// Case sensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcmp(S,AString.S);

  if (Num==0)
    Result=true;
  else
    Result=false;

  return Result;
}




bool StringC::NotEqual(const StringC &AString)
// Case sensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcmp(S,AString.S);

  if (Num==0)
    Result=false;
  else
    Result=true;

  return Result;
}




bool StringC::Greater(const StringC &AString)
// Case sensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcmp(S,AString.S);

  if (Num>0)
    Result=true;
  else
    Result=false;

  return Result;
}




bool StringC::Less(const StringC &AString)
// Case sensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcmp(S,AString.S);

  if (Num<0)
    Result=true;
  else
    Result=false;

  return Result;
}




bool StringC::Equal(const char *AString)
// Case sensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcmp(S,AString);

  if (Num==0)
    Result=true;
  else
    Result=false;

  return Result;
}




bool StringC::NotEqual(const char *AString)
// Case sensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcmp(S,AString);

  if (Num==0)
    Result=false;
  else
    Result=true;

  return Result;
}




bool StringC::Greater(const char *AString)
// Case sensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcmp(S,AString);

  if (Num>0)
    Result=true;
  else
    Result=false;

  return Result;
}




bool StringC::Less(const char *AString)
// Case sensitive StringC comparison
{
  bool Result;
  int Num;

  Num=strcmp(S,AString);

  if (Num<0)
    Result=true;
  else
    Result=false;

  return Result;
}




const char *StringC::GetS()
// Returns (char *) S.
{
  return S;
}




bool StringC::ToInt(int &Integer)
// Converts S to an integer returning true if successful and false otherwise.
{
  // We need to be able to view a variable as a long integer and an integer
  // at the same time and unions allow us to do this. In this way we can
  // convert S to a long integer and then return it as a integer if it is
  // in range.
  typedef union{int Int;long Long;} ConverterType;
  ConverterType Converter;
  const char Zero=48;
  const char Nine=57;
  const char Minus=45;
  int Index,Sign;
  bool Result;

  // If the first character is a minus sign and there are more characters
  // then set Sign to -1, which the integer is later multiplied by.
  if ((S[0]==Minus) && (L>1))
  {
    Sign=-1;
    Result=true;
    // Index starts at one since the first character has been processed.
    Index=1;
  }
  // If the first character is a digit then convert it to the integer it
  // represents.
  else if ((S[0]>=Zero) && (S[0]<=Nine))
  {
    Converter.Long=(S[0]-Zero)*10;
    Result=true;
    Sign=1;
    // Index starts at one since the first character has been processed.
    Index=1;
  }
  // Otherwise set Result to false so that no further action is taken.
  else
  {
    Integer=0;
    Result=false;
  }
  // While Result is still true continue converting S.
  while ((Index<L) && Result)
  {
    Result=((S[Index]>=Zero) && (S[Index]<=Nine));
    if (Result)
    {
      Converter.Long+=S[Index]-Zero;
      // Only want to multiply by ten if processing the last character.
      if (Index<(L-1))
        Converter.Long*=10;
      Index++;
    }
  }
  // If S was successfully converted.
  if (Result)
  {
    Converter.Long*=Sign;
    // Check if value is out of range for an integer.
    if ((Converter.Long<-32768) || (Converter.Long>32767))
    {
      Result=false;
      Integer=0;
    }
    else
    {
      Result=true;
      Integer=Converter.Int;
    }
  }
  return Result;
}




void StringC::Set(const char Ch)
{
  strset_(S,Ch,L);
  // In case Ch is EOS.
  L=strlen(S);
}

Newsgroups: comp.os.msdos.djgpp
Subject: Compiler error?????
Summary: 
Followup-To: 
Distribution: world
Organization: Comp.Sci & Comp.Eng, La Trobe Uni, Australia
Keywords: 

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019