IOFunctions.cpp
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 2012 SCHUNK GmbH & Co. KG
00003  * Copyright (c) 2017 Fraunhofer Institute for Manufacturing Engineering and Automation (IPA)
00004  *
00005  * Licensed under the Apache License, Version 2.0 (the "License");
00006  * you may not use this file except in compliance with the License.
00007  * You may obtain a copy of the License at
00008  *
00009  *   http://www.apache.org/licenses/LICENSE-2.0
00010 
00011  * Unless required by applicable law or agreed to in writing, software
00012  * distributed under the License is distributed on an "AS IS" BASIS,
00013  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
00014  * See the License for the specific language governing permissions and
00015  * limitations under the License.
00016  */
00017 
00018 #include "IOFunctions.h"
00019 #include <string.h>
00020 
00021 int util_ignore(int iSize, char cDelimiter, FILE* hFileHandle)
00022 {
00023         char cChar;
00024         for(int i = 0; i < iSize; i++)
00025         {
00026                 cChar = fgetc(hFileHandle);
00027                 if(cChar == EOF)
00028                         return -1;
00029                 if(cChar == cDelimiter)
00030                         return 0;
00031         }
00032         return 0;
00033 }
00034 
00035 int util_skipWhiteSpace(FILE* hFileHandle)
00036 {
00037         char cChar;
00038         do
00039         {
00040                 cChar = fgetc(hFileHandle);
00041                 if(cChar == EOF)
00042                         return -1;
00043                 if(cChar != ' ' && cChar != '"' && cChar != '\t')
00044                 {
00045                         ungetc(cChar, hFileHandle);
00046                         return 0;
00047                 }
00048         }while(1);
00049         return 0;
00050 }
00051 
00052 int util_getStringCutWhiteSpace(char* acReturnString, int iSize, FILE* hFileHandle)
00053 {
00054         char cChar;
00055         fgets(acReturnString, iSize, hFileHandle);
00056         for(int i = 0; i < iSize; i++)
00057         {
00058                 cChar = acReturnString[i];
00059                 if(cChar == ' ' || cChar == '"' || cChar == '#' || cChar == ';' || cChar == '\t' || cChar == '\r' || cChar == '\n' || cChar == '\0')
00060                 {
00061                         acReturnString[i] = '\0';
00062                         break;
00063                 }
00064         }
00065         return 0;
00066 }
00067 
00068 int util_searchSection(const char* acSectionName, FILE* hFileHandle)
00069 {
00070         int iRetVal = 1;
00071         int iSectionLength;
00072         char cChar;
00073         char acBuffer[512];
00074         iSectionLength = strlen(acSectionName);
00075         do
00076         {
00077                 cChar = fgetc(hFileHandle);
00078                 if(cChar == EOF)                                                // check for end of file
00079                         iRetVal = -1;
00080                 else if(cChar == '#' || cChar == ';')   // check for comment
00081                 {
00082                         iRetVal = util_ignore(0x7FFF,'\n', hFileHandle);                // skip all characters up to '\n'
00083                         if(iRetVal == 0)
00084                                 iRetVal = 1;
00085                 }
00086                 else if(cChar == '[')                                   // no comment so parse it
00087                 {
00088                         fgets(acBuffer, iSectionLength+1, hFileHandle);
00089 
00090                         if(strncmp(acBuffer, acSectionName, iSectionLength) == 0)
00091                         {
00092                                 cChar = fgetc(hFileHandle);
00093                                 if(cChar == ']')
00094                                         iRetVal = util_ignore(0x7FFF,'\n', hFileHandle);        // skip all characters up to '\n'
00095                                 else
00096                                         iRetVal = -1;
00097                         }
00098                 }
00099         }
00100         while(iRetVal > 0);
00101         return iRetVal;
00102 }
00103 
00104 int util_searchKey(const char* acKeyName, FILE* hFileHandle)
00105 {
00106         int iRetVal = 1;
00107         int iKeyLength, iBufferLength;
00108         char cChar;
00109         char acBuffer[512];
00110         iKeyLength = strlen(acKeyName);
00111         do
00112         {
00113                 cChar = fgetc(hFileHandle);
00114                 if(cChar == EOF)                                                // check for end of file
00115                         iRetVal = -1;
00116                 else if(cChar == '[')                                   // check for new section
00117                 {
00118                         ungetc(cChar, hFileHandle);
00119                         iRetVal = -1;
00120                 }
00121                 else if(cChar == '#' || cChar == ';')   // check for comment
00122                 {
00123                         iRetVal = util_ignore(0x7FFF,'\n', hFileHandle);                // skip all characters up to '\n'
00124                         if(iRetVal == 0)
00125                                 iRetVal = 1;
00126                 }
00127                 else if(cChar != ' ' && cChar != '\t' && cChar != '\r' && cChar != '\n')        // no comment or whitespace so parse it
00128                 {
00129                         acBuffer[0] = cChar;
00130                         if (iKeyLength > 1)
00131                                 fgets(acBuffer + 1, iKeyLength, hFileHandle);
00132 
00133                         iBufferLength = strlen(acBuffer);
00134                         if(iBufferLength > iKeyLength || (iBufferLength == iKeyLength && acBuffer[iBufferLength - 1] != '\n'))
00135                         {
00136                                 if(strncmp(acBuffer, acKeyName, iKeyLength) == 0)
00137                                 {
00138                                         iRetVal = util_skipWhiteSpace(hFileHandle);
00139                                         cChar = fgetc(hFileHandle);
00140                                         if(cChar == '=')                         // check for delimiter
00141                                                 iRetVal = util_skipWhiteSpace(hFileHandle);
00142                                         else
00143                                                 return -1;
00144                                 }
00145                                 else
00146                                 {
00147                                         iRetVal = util_ignore(0x7FFF,'\n', hFileHandle);                // skip all characters up to '\n'
00148                                         if(iRetVal == 0)
00149                                                 iRetVal = 1;
00150                                 }
00151                         }
00152                 }
00153         }
00154         while(iRetVal > 0);
00155         return iRetVal;
00156 }
00157 
00158 int util_searchString(const char* acSectionName, const char* acKeyName, const char* acDefaultString, char* acReturnString, int iSize, const char* acFileName)
00159 {
00160         FILE* hFileHandle = fopen( acFileName, "r" );
00161         if(hFileHandle <= 0)
00162         {
00163                 strncpy(acReturnString, acDefaultString, iSize);
00164                 return -1;
00165         }
00166 
00167         if(util_searchSection(acSectionName, hFileHandle) < 0)
00168         {
00169                 strncpy(acReturnString, acDefaultString, iSize);
00170                 fclose(hFileHandle);
00171                 return 0;
00172         }
00173         if(util_searchKey(acKeyName, hFileHandle) < 0)
00174         {
00175                 strncpy(acReturnString, acDefaultString, iSize);
00176                 fclose(hFileHandle);
00177                 return 0;
00178         }
00179         util_getStringCutWhiteSpace(acReturnString, iSize, hFileHandle);
00180         fclose(hFileHandle);
00181         return strlen(acReturnString);
00182 }
00183 
00184 int util_setSection(const char* acSectionName, FILE* hFileHandle)
00185 {
00186         int iRetVal = fseek(hFileHandle,0,SEEK_CUR);
00187         if(iRetVal < 0)
00188         {
00189 //              std::cout << "Section set error" << std::endl;
00190                 return -1;
00191         }
00192         iRetVal = fprintf(hFileHandle, "\n\n[%s]", acSectionName);
00193         if(iRetVal == strlen(acSectionName) + 4)
00194         {
00195 //              std::cout << "Section set" << std::endl;
00196                 fseek(hFileHandle,0,SEEK_CUR);
00197                 return 0;
00198         }
00199         else
00200         {
00201 //              std::cout << "Section set error" << std::endl;
00202                 return -1;
00203         }
00204 }
00205 
00206 int util_setKey(const char* acKeyName, FILE* hFileHandle)
00207 {
00208         int iRetVal = fseek(hFileHandle,0,SEEK_CUR);
00209         if(iRetVal < 0)
00210         {
00211 //              std::cout << "Section set error" << std::endl;
00212                 return -1;
00213         }
00214         iRetVal = fprintf(hFileHandle, "\n%s = ", acKeyName);
00215         if(iRetVal == strlen(acKeyName) + 4)
00216         {
00217 //              std::cout << "Key set" << std::endl;
00218                 fseek(hFileHandle,0,SEEK_CUR);
00219                 return 0;
00220         }
00221         else
00222         {
00223 //              std::cout << "Key set error" << std::endl;
00224                 return -1;
00225         }
00226 }
00227 
00228 int util_setString(const char* acSectionName, const char* acKeyName, const char* acString, const char* acFileName)
00229 {
00230         int iRetVal = 0;
00231         int iLength = 0;
00232         char* acBuffer = NULL;
00233         FILE* hFileHandle = fopen( acFileName, "r+" );
00234         if(hFileHandle <= 0)
00235         {
00236                 hFileHandle = fopen( acFileName, "w+" );
00237                 if(hFileHandle <= 0)
00238                 {
00239 //                      std::cout << "File open error" << std::endl;
00240                         return -1;
00241                 }
00242         }
00243 //      std::cout << "File open" << std::endl;
00244         if(util_searchSection(acSectionName, hFileHandle) < 0)
00245         {
00246 //              std::cout << "Section not found" << std::endl;
00247                 iRetVal = util_setSection(acSectionName, hFileHandle);
00248                 if(iRetVal < 0)
00249                 {
00250                         fclose(hFileHandle);
00251                         return -1;
00252                 }
00253         }
00254 //      else
00255 //              std::cout << "Section found" << std::endl;
00256         if(util_searchKey(acKeyName, hFileHandle) < 0)
00257         {
00258 //              std::cout << "Key not found" << std::endl;
00259                 fpos_t fposRest;
00260                 iRetVal = fgetpos(hFileHandle, &fposRest);
00261                 if(iRetVal < 0)
00262                 {
00263 //                      std::cout << "get Rest pos error" << std::endl;
00264                         fclose(hFileHandle);
00265                         return -1;
00266                 }
00267                 char cChar;
00268                 do
00269                 {
00270 #if defined(__LINUX__)
00271                         fposRest.__pos--;
00272 #else
00273                         fposRest--;
00274 #endif
00275                         iRetVal = fsetpos(hFileHandle, &fposRest);
00276                         if(iRetVal < 0)
00277                         {
00278 //                              std::cout << "set Rest pos error" << std::endl;
00279                                 fclose(hFileHandle);
00280                                 return -1;
00281                         }
00282                         cChar = fgetc(hFileHandle);
00283                         if(cChar != '\n')
00284                         {
00285 #if defined(__LINUX__)
00286                                 fposRest.__pos++;
00287 #else
00288                                 fposRest++;
00289 #endif
00290                                 iRetVal = fsetpos(hFileHandle, &fposRest);
00291                                 if(iRetVal < 0)
00292                                 {
00293 //                                      std::cout << "set Rest pos error" << std::endl;
00294                                         fclose(hFileHandle);
00295                                         return -1;
00296                                 }
00297                                 break;
00298                         }
00299                 }while(1);
00300 
00301                 do
00302                 {
00303                         cChar = fgetc(hFileHandle);
00304                         if(cChar == EOF)
00305                                 break;
00306                 }while(1);
00307                 fpos_t fposEnd;
00308                 iRetVal = fgetpos(hFileHandle, &fposEnd);
00309                 if(iRetVal < 0)
00310                 {
00311 //                      std::cout << "get End pos error" << std::endl;
00312                         fclose(hFileHandle);
00313                         return -1;
00314                 }
00315 #if defined(__LINUX__)
00316                 iLength = fposEnd.__pos - fposRest.__pos;
00317 #else
00318                 iLength = fposEnd - fposRest;
00319 #endif
00320                 if(iLength > 0)
00321                 {
00322                         acBuffer = new char[iLength];
00323         //              std::cout << "Rest length: " << iLength << std::endl;
00324 
00325                         iRetVal = fsetpos(hFileHandle, &fposRest);
00326                         if(iRetVal < 0)
00327                         {
00328         //                      std::cout << "set Rest pos error" << std::endl;
00329                                 fclose(hFileHandle);
00330                                 if(acBuffer != NULL)
00331                                         delete[] acBuffer;
00332                                 return -1;
00333                         }
00334                                         
00335                         iLength = fread(acBuffer, sizeof(char), iLength, hFileHandle);
00336                         if(iLength < 0)
00337                         {
00338         //                      std::cout << "read Rest error" << std::endl;
00339                                 fclose(hFileHandle);
00340                                 if(acBuffer != NULL)
00341                                         delete[] acBuffer;
00342                                 return -1;
00343                         }
00344                         acBuffer[iLength] = '\0';
00345                 }
00346 //              std::cout << "read Rest:" << acBuffer << std::endl;
00347                 iRetVal = fsetpos(hFileHandle, &fposRest);
00348                 if(iRetVal < 0)
00349                 {
00350 //                      std::cout << "set String pos error" << std::endl;
00351                         fclose(hFileHandle);
00352                         if(acBuffer != NULL)
00353                                 delete[] acBuffer;
00354                         return -1;
00355                 }
00356                 iRetVal = util_setKey(acKeyName, hFileHandle);
00357                 if(iRetVal < 0)
00358                 {
00359                         fclose(hFileHandle);
00360                         if(acBuffer != NULL)
00361                                 delete[] acBuffer;
00362                         return -1;
00363                 }
00364                 iRetVal = fprintf(hFileHandle, "%s", acString);
00365                 if(iRetVal != strlen(acString))
00366                 {
00367 //                      std::cout << "String set error" << std::endl;
00368                         fclose(hFileHandle);
00369                         if(acBuffer != NULL)
00370                                 delete[] acBuffer;
00371                         return -1;
00372                 }
00373 //              else
00374 //                      std::cout << "String set" << std::endl;
00375                 if(iLength > 0)
00376                 {
00377                         iLength = fwrite(acBuffer, sizeof(char), iLength, hFileHandle);
00378                         if(iLength != iLength)
00379                         {
00380         //                      std::cout << "write Rest error" << std::endl;
00381                                 fclose(hFileHandle);
00382                                 if(acBuffer != NULL)
00383                                         delete[] acBuffer;
00384                                 return -1;
00385                         }
00386                         if(acBuffer != NULL)
00387                                 delete[] acBuffer;
00388                 }
00389         }
00390         else
00391         {       
00392 //              std::cout << "Key found" << std::endl;
00393                 fpos_t fposString;
00394                 iRetVal = fgetpos(hFileHandle, &fposString);
00395                 if(iRetVal < 0)
00396                 {
00397 //                      std::cout << "get String pos error" << std::endl;
00398                         fclose(hFileHandle);
00399                         return -1;
00400                 }
00401                 
00402                 char cChar;
00403                 int iErase = 0;
00404                 do
00405                 {
00406                         cChar = fgetc(hFileHandle);
00407                         if(cChar == EOF || cChar == '\n' || cChar == ';' || cChar == '#')
00408                         {
00409                                 ungetc(cChar, hFileHandle);
00410                                 break;
00411                         }
00412                         iErase++;
00413                 }while(1);
00414                 fpos_t fposRest;
00415                 iRetVal = fgetpos(hFileHandle, &fposRest);
00416                 if(iRetVal < 0)
00417                 {
00418 //                      std::cout << "get Rest pos error" << std::endl;
00419                         fclose(hFileHandle);
00420                         return -1;
00421                 }
00422 
00423                 do
00424                 {
00425                         cChar = fgetc(hFileHandle);
00426                         if(cChar == EOF)
00427                                 break;
00428                 }while(1);
00429                 fpos_t fposEnd;
00430                 iRetVal = fgetpos(hFileHandle, &fposEnd);
00431                 if(iRetVal < 0)
00432                 {
00433                         std::cout << "get End pos error" << std::endl;
00434                         fclose(hFileHandle);
00435                         return -1;
00436                 }
00437 #if defined(__LINUX__)
00438                 iLength = fposEnd.__pos - fposRest.__pos;
00439 #else
00440                 iLength = fposEnd - fposRest;
00441 #endif
00442                 if(iLength > 0)
00443                 {
00444                         acBuffer = new char[iLength];
00445         //              std::cout << "Rest length: " << iLength << std::endl;
00446 
00447                         iRetVal = fsetpos(hFileHandle, &fposRest);
00448                         if(iRetVal < 0)
00449                         {
00450         //                      std::cout << "set Rest pos error" << std::endl;
00451                                 fclose(hFileHandle);
00452                                 if(acBuffer != NULL)
00453                                         delete[] acBuffer;
00454                                 return -1;
00455                         }
00456                                         
00457                         iLength = fread(acBuffer, sizeof(char), iLength, hFileHandle);
00458                         if(iLength < 0)
00459                         {
00460         //                      std::cout << "read Rest error" << std::endl;
00461                                 fclose(hFileHandle);
00462                                 if(acBuffer != NULL)
00463                                         delete[] acBuffer;
00464                                 return -1;
00465                         }
00466                         acBuffer[iLength] = '\0';
00467                 }
00468 //              std::cout << "read Rest:" << acBuffer << std::endl;
00469                 iRetVal = fsetpos(hFileHandle, &fposString);
00470                 if(iRetVal < 0)
00471                 {
00472 //                      std::cout << "set String pos error" << std::endl;
00473                         fclose(hFileHandle);
00474                         if(acBuffer != NULL)
00475                                 delete[] acBuffer;
00476                         return -1;
00477                 }
00478 
00479                 iRetVal = fprintf(hFileHandle, "%s ", acString);
00480                 iErase -= strlen(acString) + 1;
00481                 if(iRetVal != strlen(acString) + 1)
00482                 {
00483 //                      std::cout << "String set error" << std::endl;
00484                         fclose(hFileHandle);
00485                         if(acBuffer != NULL)
00486                                 delete[] acBuffer;
00487                         return -1;
00488                 }
00489 //              else
00490 //                      std::cout << "String set" << std::endl;
00491 
00492                 if(iLength > 0)
00493                 {
00494                         iLength = fwrite(acBuffer, sizeof(char), iLength, hFileHandle);
00495                         if(iLength != iLength)
00496                         {
00497         //                      std::cout << "write Rest error" << std::endl;
00498                                 fclose(hFileHandle);
00499                                 if(acBuffer != NULL)
00500                                         delete[] acBuffer;
00501                                 return -1;
00502                         }
00503         //              std::cout << "erase " << iErase << std::endl;
00504                         for(int i = 0; i < iErase; i++)
00505                         {
00506                                 cChar = fputc('\0', hFileHandle);
00507                                 if(cChar == EOF)
00508                                         break;
00509                         }
00510                         if(acBuffer != NULL)
00511                                 delete[] acBuffer;
00512                 }
00513         }
00514         fclose(hFileHandle);
00515         return 0;
00516 }
00517 
00518 // -------------------------------------------------------------------------- ;
00519 
00520 //\fdd{ This function helps to read input formatted as keyword (or phrase),
00521 //              number (optional), delimiter, followed by an argument, which will be
00522 //              read by some other function. Leading white space and comments
00523 //              (everything from a '#' or ';' sign until the end of that line) will be
00524 //              skipped. The next std::string (including any white space) will be compared
00525 //              against the keyword. If this does not match the function returns
00526 //              imediately and indicates the error. If the number is positive
00527 //              (including zero) the next std::string after skipping white space will be
00528 //              read in as an integral number. If the numbers are not equal the
00529 //              function returns and indicates the error. Otherwise white space will
00530 //              be skipped and the next character will be compared with the delimiter.
00531 //              In case of mismatch the function returns an error code, otherwise it
00532 //              skips white space a last time. Now the stream should be positioned at
00533 //              the argument, which could be read by an adequate read function. }
00534 //\xmp{ The following examples could be processed by this function:
00535 //              \begin{itemize}
00536 //                      \item   \verb|count of events = 5|
00537 //                      \item   \verb|item 001: first item|
00538 //                      \item   \verb|position = [ 12, 34 ]|
00539 //                      \item   \verb|circle:|\newline
00540 //                                      \verb|center = [ 43, 21]|\newline
00541 //                                      \verb|radius = 7|
00542 //              \end{itemize}
00543 //              In the last example \texttt{circle} is the keyword, no number is used
00544 //              and the delimiter is a colon. Therefore the corresponding call to this
00545 //              function would look as follows:\newline
00546 //              \begin{quote}
00547 //                      \verb|error = posArgForKey(inL, "circle", -1, ':');|\newline
00548 //              \end{quote}
00549 //              This function will check for "circle" and the colon. Then it positions
00550 //              the stream just ahead of the std::string "center". Given a class
00551 //              \texttt{circle} with a method read able to process this format, we
00552 //              could just call:\newline
00553 //              \begin{quote}
00554 //                      \verb|circle::read(inL);|\newline
00555 //              \end{quote}
00556 //              in order to read the circle from the input stream. }
00557 //\arg{ in:             a reference to an input stream }
00558 //\arg{ key:    the keyword (or phrase) to look for }
00559 //\arg{ number: an optional number following the keyword }
00560 //\arg{ delim:  the sign preceeding the argument for the given keyword }
00561 //\ret{ The constant \texttt{OKAY} indicates successful operation. In case of
00562 //              an error the following cases are distinguished:
00563 //              \begin{itemize}
00564 //                      \item   \texttt{NO\_KEY} the keyword did not match
00565 //                      \item   \texttt{KEY\_BUT\_WRONG\_NUMBER} the number did not match
00566 //                      \item   \texttt{KEY\_BUT\_NO\_EQUAL} the delimiter did not match
00567 //                      \item   \texttt{FOUND\_EOF} EOF reached
00568 //              \end{itemize}. }
00569 
00570 #ifdef WITHSTREAMS
00571 int util_posArgForKey(
00572                 std::istream&           in,
00573                 const char*             key,
00574                 int                             number,
00575                 char                    delim)
00576 {
00577         static char buf[BUFFER_LENGTH];
00578            char cL;
00579            int  count;
00580         
00581         while( !in.eof() )
00582         {
00583                 in >> cL;
00584 
00585                 if(cL == '#' || cL == ';')      // check for comment
00586                         in.ignore(0x7FFF,'\n'); // skip all characters up to '\n'
00587                 else                                            // no comment so parse it
00588                 {
00589                         buf[0] = cL;
00590 
00591                         if (strlen(key) > 1)  // Workaround for bug in WATCOM's std::istream::get
00592                                 in.get(buf+1, strlen(key), '\n');
00593 
00594                         if(strncmp(buf, key, strlen(key)) == 0)
00595                         {
00596                                 if (number >= 0)
00597                                 {
00598                                         in >> count;
00599                                         
00600                                         if (count != number)
00601                                                 return KEY_BUT_WRONG_NUMBER;
00602                                 };
00603                                 
00604                                 in >> std::ws;         // skip whitespace
00605                                 in >> cL;
00606                                 if(cL == delim)   // check for delimiter
00607                                 {
00608                                         // skip whitespace
00609                                         
00610                                         in >> std::ws;
00611                                         
00612                                         // the argument should follow now
00613                                         
00614                                         return OKAY;
00615                                 }
00616                                 else
00617                                         return KEY_BUT_NO_EQUAL;
00618                         }       
00619                         else
00620                                 return NO_KEY;
00621                 };
00622         };
00623 
00624         return FOUND_EOF;
00625 };      
00626 
00627 // -------------------------------------------------------------------------- ;
00628 /* \fdd{Generates error messsages according to an error status for example generated 
00629 by posArgForKey(..)} 
00630 */
00631 void util_parseError(
00632                 int                             status,
00633                 const char*             key,
00634                 int                             number)
00635 {
00636         switch(status)
00637         {
00638                 case OKAY:
00639                         break;
00640                 case KEY_BUT_NO_EQUAL:
00641                         std::cerr << "\nread(in) parse error : '=' expected behind";
00642                         std::cerr << key;
00643                         if (number >= 0)
00644                                 std::cerr << " " << number;
00645                         std::cerr << " !";
00646                         break;
00647                 case NO_KEY:
00648                         std::cerr << "\nread(in) parse error : '";
00649                         std::cerr << key;
00650                         if (number >= 0)
00651                                 std::cerr << " " << number;
00652                         std::cerr << "' expected !";
00653                         break;
00654                 case FOUND_EOF:
00655                         std::cerr << "\nread(in) parse error : premature EOF '";
00656                         std::cerr << key;
00657                         if (number >= 0)
00658                                 std::cerr << " " << number;
00659                         std::cerr << "' expected !";
00660                         break;
00661                 case NO_OPEN_BRACKET:
00662                         std::cerr << "\nread(in) parse error : '[' expected before";
00663                         std::cerr << key;
00664                         if (number >= 0)
00665                                 std::cerr << " " << number;
00666                         std::cerr << " argument !";
00667                         break;
00668                 case NO_SEPERATOR:
00669                         std::cerr << "\nread(in) parse error : ', ' expected ";
00670                         std::cerr << " between components of " << key;
00671                         if (number >= 0)
00672                                 std::cerr << " " << number;
00673                         std::cerr << " argument !";
00674                         break;
00675                 case NO_CLOSED_BRACKET:
00676                         std::cerr << "\nread(in) parse error : ']' expected behind";
00677                         std::cerr << key;
00678                         if (number >= 0)
00679                                 std::cerr << " " << number;
00680                         std::cerr << " argument !";
00681                         break;
00682                 default:
00683                         std::cerr << "\nread(in) : unknown error !?!?!?!?!?!?!?!?!";
00684                         break;
00685         };
00686 };
00687 
00688 // -------------------------------------------------------------------------- ;
00689 /*
00690 \fdd{combines posArgForKey(..) and parseError(..) to one function call.}
00691 \arg{std::istream& inA}
00692 \arg{const char* const keyA}
00693 \arg{int numberA}
00694 \arg{char delimA}
00695 \ret{{\tt const int} is returned. If eof occured before anything else than 
00696   FOUND\_EOF is returned. If no key was found NO\_KEY is returned. 
00697   If a key was found but the wrong number followed KEY\_BUT\_WRONG\_NUMBER is returned.
00698   If a key was found, the number was negativ and no equal sign followed KEY\_BUT\_NO\_EQUAL 
00699   is returned. }
00700 */
00701 void util_posArgForKeyWithCheck(
00702                 std::istream&   in, 
00703                 const char*             key, 
00704                 int                             number, 
00705                 char                    delim )
00706 {
00707         int        status;
00708         
00709         status = util_posArgForKey(in, key, number, delim);
00710         
00711         if(status != OKAY)
00712                 util_parseError(status, key);
00713 };
00714 
00715 #endif


schunk_libm5api
Author(s): Florian Weisshardt
autogenerated on Sat Jun 8 2019 20:25:13