00001 00002 /****************************************************************************** 00003 * 00004 * Copyright (c) 2012 00005 * 00006 * SCHUNK GmbH & Co. KG 00007 * 00008 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00009 * 00010 * Project name: Drivers for "Amtec M5 Protocol" Electronics V4 00011 * 00012 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00013 * 00014 * Email:robotics@schunk.com 00015 * 00016 * ToDo: 00017 * 00018 * ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 00019 * 00020 * Redistribution and use in source and binary forms, with or without 00021 * modification, are permitted provided that the following conditions are met: 00022 * 00023 * * Redistributions of source code must retain the above copyright 00024 * notice, this list of conditions and the following disclaimer. 00025 * * Redistributions in binary form must reproduce the above copyright 00026 * notice, this list of conditions and the following disclaimer in the 00027 * documentation and/or other materials provided with the distribution. 00028 * * Neither the name of SCHUNK GmbH & Co. KG nor the names of its 00029 * contributors may be used to endorse or promote products derived from 00030 * this software without specific prior written permission. 00031 * 00032 * This program is free software: you can redistribute it and/or modify 00033 * it under the terms of the GNU Lesser General Public License LGPL as 00034 * published by the Free Software Foundation, either version 3 of the 00035 * License, or (at your option) any later version. 00036 * 00037 * This program is distributed in the hope that it will be useful, 00038 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00039 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00040 * GNU Lesser General Public License LGPL for more details. 00041 * 00042 * You should have received a copy of the GNU Lesser General Public 00043 * License LGPL along with this program. 00044 * If not, see <http://www.gnu.org/licenses/>. 00045 * 00046 ******************************************************************************/ 00047 00048 00049 #ifndef UTIL_IOFUNCTIONS_H 00050 #define UTIL_IOFUNCTIONS_H 00051 00052 // ---- global includes ----------------------------------------------------- ; 00053 00054 #include "../Util/GlobalDefines.h" 00055 #include <stdio.h> 00056 #include <stdlib.h> // to use getenv 00057 #include <iostream> 00058 00059 #if defined(__QNX__) && defined(__WATCOMC__) 00060 #include <iomanip> 00061 #endif 00062 00063 // ---- constants ----------------------------------------------------------- ; 00064 00065 const int BUFFER_LENGTH = 256; 00066 00067 const int OKAY = 0; 00068 const int KEY_BUT_NO_EQUAL = 1; 00069 const int NO_KEY = 2; 00070 const int FOUND_EOF = 3; 00071 const int NO_OPEN_BRACKET = 4; 00072 const int NO_SEPERATOR = 5; 00073 const int NO_CLOSED_BRACKET = 6; 00074 const int KEY_BUT_WRONG_NUMBER = 7; 00075 00076 // ---- local includes ------------------------------------------------------ ; 00077 00078 // ---- local functions ----------------------------------------------------- ; 00079 00080 int util_searchString(const char* acSectionName, const char* acKeyName, const char* acDefaultString, char* acReturnString, int iSize, const char* acFileName); 00081 00082 int util_setString(const char* acSectionName, const char* acKeyName, const char* acString, const char* acFileName); 00083 00084 #ifdef WITHSTREAMS 00085 // checks for a given keyword and positions the stream at the 00086 // corresponding argument 00087 int util_posArgForKey( 00088 std::istream& clIn, 00089 const char* acKey, 00090 int iNumber = -1, 00091 char cDelim = '='); 00092 00093 // generates error messsages according to a error status 00094 // returned for example by posArgForKey(..) 00095 void util_parseError(int iStatus, 00096 const char* acKey, 00097 int iNumber = -1); 00098 00099 // combines posArgForKey(..) and parseError(..) to one function call 00100 void util_posArgForKeyWithCheck( 00101 std::istream& clIn, 00102 const char* acKey, 00103 int iNumber = -1, 00104 char cDelim = '='); 00105 00106 #endif // WITHSTREAMS 00107 #endif // UTIL_IOFUNCTIONS_H