home *** CD-ROM | disk | FTP | other *** search
- /*-- Rev Header - do NOT edit!
- *
- * Filename : cina.cc
- * Purpose : (Erst einmal) Ersatz von istream, e.g. cin
- *
- * Program : -
- * Author : Gerhard Müller
- * Copyright: (c) by Gerhard Müller
- * Creation :
- *
- * compile : make
- *
- * Compile version : 0.1
- * Ext. Version : 0.1
- *
- * REVISION HISTORY
- *
- * Date Comment
- * ------------------------ -------------------------------------------------
- * Fri Sep 17 00:39:53 1993 Seems to work quite well.
- *
- *-- REV_END --
- */
-
- /*
- * C++-Includes, C++-Definitionen
- *
- */
-
-
- #include "cina.h"
-
- cina& cina::operator>>(long& return_val)
- {
- look_tie();
-
- int base = 10;
- int ndigits = 0;
- int neg;
- int val;
-
- register int ch = skip_ws(*this);
-
- if (ch == EOF)
- goto eof_fail;
-
- neg = 0;
-
- if (ch == '+')
- {
- ch = skip_ws(*this);
- }
- else if (ch == '-')
- {
- neg = 1;
- ch = skip_ws(*this);
- }
-
- if (ch == EOF) goto eof_fail;
-
- // if (!(stream.flags() & ios::basefield)) {
-
- if (ch == '0')
- {
- ch = FGetC(_fh);
-
- if (ch == EOF)
- {
- val = 0;
- goto ok;
- }
-
- if (ch == 'x' || ch == 'X')
- {
- base = 16;
- ch = FGetC(_fh);
- if (ch == EOF) goto eof_fail;
- }
- else
- {
- UnGetC(_fh,ch);
- base = 8;
- ch = '0';
- }
- }
-
- // }
- // else if ((stream.flags() & ios::basefield) == ios::hex)
- // base = 16;
- // else if ((stream.flags() & ios::basefield) == ios::oct)
- // base = 8;
-
-
- val = 0;
-
- for (;;)
- {
- if (ch == EOF)
- break;
-
- int digit;
-
- if (ch >= '0' && ch <= '9')
- digit = ch - '0';
- else if (ch >= 'A' && ch <= 'F')
- digit = ch - 'A' + 10;
- else if (ch >= 'a' && ch <= 'f')
- digit = ch - 'a' + 10;
- else
- digit = 999;
-
- if (digit >= base)
- {
- UnGetC(_fh,ch);
-
- if (ndigits == 0)
- goto fail;
- else
- goto ok;
- }
-
- ndigits++;
- val = base * val + digit;
- ch = FGetC(_fh);
- }
- ok:
- if(neg) val=-val;
- return_val=val;
- return *this;
-
- fail:
- return_val=0;
- set(ios::failbit);
- return *this;
-
- eof_fail:
- return_val=0;
- set(ios::failbit|ios::eofbit);
- return *this;
- }
-
-
-
-
- cina cin;
-
-