Main Page | Namespace List | Class Hierarchy | Compound List | File List | Namespace Members | Compound Members | File Members

abkio.cxx

Go to the documentation of this file.
00001 /**************************************************************************
00002 ***    
00003 *** Copyright (c) 1995-2000 Regents of the University of California,
00004 ***               Andrew E. Caldwell, Andrew B. Kahng and Igor L. Markov
00005 *** Copyright (c) 2000-2004 Regents of the University of Michigan,
00006 ***               Saurabh N. Adya, Jarrod A. Roy and Igor L. Markov
00007 ***
00008 ***  Contact author(s): abk@cs.ucsd.edu, imarkov@umich.edu
00009 ***  Original Affiliation:   UCLA, Computer Science Department,
00010 ***                          Los Angeles, CA 90095-1596 USA
00011 ***
00012 ***  Permission is hereby granted, free of charge, to any person obtaining 
00013 ***  a copy of this software and associated documentation files (the
00014 ***  "Software"), to deal in the Software without restriction, including
00015 ***  without limitation 
00016 ***  the rights to use, copy, modify, merge, publish, distribute, sublicense, 
00017 ***  and/or sell copies of the Software, and to permit persons to whom the 
00018 ***  Software is furnished to do so, subject to the following conditions:
00019 ***
00020 ***  The above copyright notice and this permission notice shall be included
00021 ***  in all copies or substantial portions of the Software.
00022 ***
00023 *** THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 
00024 *** EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
00025 *** OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 
00026 *** IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
00027 *** CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
00028 *** OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
00029 *** THE USE OR OTHER DEALINGS IN THE SOFTWARE.
00030 ***
00031 ***
00032 ***************************************************************************/
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 // Aug 27, 1997   Igor Markov  VLSI CAD UCLA ABKGROUP
00045 
00046 // CHANGES
00047 // 980212 ilm renamed into abkio.cxx
00048 //            added printRange() and some more from abkio.h
00049 // 980320 ilm added optional lineNo argument to asserting IO manipulators
00050 
00051 #ifdef _MSC_VER
00052 #pragma warning(disable:4786)
00053 #endif
00054 
00055 
00056 #include <iostream>
00057 #include <iomanip>
00058 #include <ctype.h>
00059 #include <stdio.h>
00060 #include "abkstring.h"
00061 #include "abkassert.h"
00062 #include "abkio.h"
00063 #define eh eathash
00064 
00065 istream& eatblank(istream& i)
00066 {
00067   while (i.peek()==' ' || i.peek()=='\t') i.get();
00068   return i;
00069 }
00070 
00071 istream& skiptoeol(istream& i)
00072 {
00073   while (!i.eof() && i.peek()!='\n' && i.peek()!='\r') i.get();
00074 //if (i.peek() == '\n' || i.peek() == '\r') i.get();
00075   return i;
00076 }
00077 
00078 
00079 // ================ Now go arrangements for manipulators with arguments
00080 
00081 istream& impl_eathash(istream& i, int& lineNo)
00082 {
00083    bool noLineNo=(lineNo==-1);
00084    i >> eatblank;
00085    while (i.peek() == '\n' || i.peek() == '\r')
00086    { 
00087       lineNo++; i.get();
00088       i >> eatblank;
00089    }
00090    // if (i.peek()!='#' && i.peek()!='\n')  {i.putback('\n'); }
00091    while (i.peek()=='#') 
00092    {
00093      while (!i.eof() && i.peek()!='\n' && i.peek()!='\r') i.get();
00094      while (!i.eof() && (i.peek()=='\n' || i.peek()=='\r')) 
00095      { i.get(); i >> eatblank; lineNo++;} 
00096    }
00097    while (i.peek() == '\n' || i.peek() == '\r')
00098    {
00099       lineNo++;
00100       i.get();
00101       i >> eatblank;
00102    }                     
00103 // if (i.peek()!='#' && i.peek()!='\n')  {i.putback('\n'); }
00104 // if (i.peek() == '\n') { i.get(); lineNo++; }
00105    if (noLineNo) lineNo=-1;
00106    return i;
00107 }
00108 
00109 istream& impl_needeol(istream& i, int lineNo=-1)
00110 {
00111    i >> eatblank;
00112    if (lineNo>0)
00113    {
00114     abkfatal2(i.peek()=='\n' || i.peek()=='\r'
00115               , " End of line expected near line ",lineNo);
00116    }
00117    else
00118    {
00119     abkfatal(i.peek()=='\n' || i.peek()=='\r', " End of line expected");
00120    }
00121    return i;
00122 }
00123 
00124 istream& impl_noeol(istream& i, int lineNo=-1)
00125 {
00126    i >> eatblank;
00127    if (lineNo>0)    
00128    {
00129      abkfatal2(i.peek()!='\n' && i.peek()!='\r'
00130                , " Unexpected end of line near line ", lineNo); 
00131    }
00132    else
00133    {
00134      abkfatal(i.peek()!='\n' && i.peek()!='\r', " Unexpected end of line");
00135    }
00136   return i;
00137 }
00138 
00139 istream& impl_isnumber(istream& i, int lineNo=-1)
00140 {
00141    i >> eatblank;
00142    char errMess[255];
00143    char c=i.peek();
00144    if (lineNo>0) sprintf(errMess," near line %d, but starts with %c ",lineNo,c);
00145    else          sprintf(errMess,", but starts with %c ",c);
00146    abkfatal2(isdigit(i.peek()) || i.peek()=='-', " Number expected",errMess);
00147    return i;
00148 }
00149 
00150 istream& impl_isword(istream& i, int lineNo=-1)
00151 {
00152    i >> eatblank;
00153    char errMess[255];
00154    char c=i.peek();
00155    if (lineNo>0) sprintf(errMess," near line %d, but starts with %c ",lineNo,c);
00156    else          sprintf(errMess,", but starts with %c ",c);
00157    abkfatal2(isalpha(c), " Word expected",errMess);
00158   return i;
00159 }
00160 
00161 istream& impl_needword(istream& in,const char* word, int lineNo=-1)
00162 {
00163    char buffer[1024], errMess[255];  // still no way to avoid buffer overflow !
00164    in >> eatblank >> buffer; 
00165    if (lineNo>0)
00166    {
00167       sprintf(errMess," '%s' expected near line %d . Got %s ",word,lineNo,buffer);
00168       abkfatal(strcmp(buffer,word)==0,errMess);
00169    }
00170    else
00171    {
00172        sprintf(errMess," '%s' expected. Got %s ",word, buffer); 
00173        abkfatal(strcmp(buffer,word)==0,errMess);
00174    }
00175    return in;
00176 }
00177 
00178 istream& impl_needcaseword(istream& in,const char* word, int lineNo=-1)
00179 {
00180    char buffer[1024], errMess[255];  // still no way to avoid buffer overflow !
00181    in >> eatblank;
00182    in >> buffer;
00183    if (lineNo>0)
00184    {
00185       sprintf(errMess," '%s' expected near line %d. Got %s ",word,lineNo, buffer);
00186       abkfatal2(strcasecmp(buffer,word)==0,errMess,lineNo);
00187    }
00188    else
00189    {
00190        sprintf(errMess," '%s' expected. Got %s ",word, buffer);
00191        abkfatal(strcasecmp(buffer,word)==0,errMess);
00192    }                
00193    return in;
00194 }
00195 
00196 ManipFuncObj2<const char *, int> needword(const char * word, int lineNo)
00197 { return ManipFuncObj2<const char *,int>(impl_needword,word, lineNo); }
00198 
00199 ManipFuncObj2<const char *, int> needcaseword(const char * word, int lineNo)
00200 { return ManipFuncObj2<const char *, int>(impl_needcaseword,word,lineNo); }
00201 
00202 ManipFuncObj1<int&> eathash(int& lineNo)
00203 { return ManipFuncObj1<int&>(impl_eathash, lineNo); }
00204 
00205 ManipFuncObj1<int> needeol(int lineNo)
00206 { return ManipFuncObj1<int>(impl_needeol, lineNo); }
00207 
00208 ManipFuncObj1<int> noeol(int lineNo)
00209 { return ManipFuncObj1<int>(impl_noeol,lineNo); }
00210 
00211 ManipFuncObj1<int> my_isnumber(int lineNo)
00212 { return ManipFuncObj1<int>(impl_isnumber,lineNo); }            
00213 
00214 ManipFuncObj1<int> isword(int lineNo)
00215 { return ManipFuncObj1<int>(impl_isword, lineNo); }
00216 

Generated on Mon Apr 25 01:09:23 2005 for Parquete by doxygen 1.3.2