00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
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
00075 return i;
00076 }
00077
00078
00079
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
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
00104
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];
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];
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