/usr/include/rheolef/inhb-aux.h is in librheolef-dev 5.93-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 | # ifndef _SKIT_INHB_AUX_H
# define _SKIT_INHB_AUX_H
///
/// This file is part of Rheolef.
///
/// Copyright (C) 2000-2009 Pierre Saramito <Pierre.Saramito@imag.fr>
///
/// Rheolef is free software; you can redistribute it and/or modify
/// it under the terms of the GNU General Public License as published by
/// the Free Software Foundation; either version 2 of the License, or
/// (at your option) any later version.
///
/// Rheolef is distributed in the hope that it will be useful,
/// but WITHOUT ANY WARRANTY; without even the implied warranty of
/// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
/// GNU General Public License for more details.
///
/// You should have received a copy of the GNU General Public License
/// along with Rheolef; if not, write to the Free Software
/// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
///
/// =========================================================================
//
// auxilliary functios for HB i/O
//
# include "rheolef/compiler.h"
namespace rheolef {
# define hb_id(file_name) \
(file_name ? file_name : "line")
# define hb_error(line_no, file_name, message) \
(std::cerr << "error: " << hb_id(file_name) << "(" << line_no << "): " << message << ".\n", exit(1), false)
# define hb_warning(line_no, file_name, message) \
(std::cerr << "warning: " << hb_id(file_name) << "(" << line_no << "): " << message << ".\n", true)
template <class Size>
inline
bool
skip_eoln (std::istream& s, const char *file_name, Size line_no)
{
if (endofline(s,Size(256)))
return true;
if (s.eof())
return hb_error (line_no, file_name, "unexpected end of file");
if (s.fail())
return hb_error (line_no, file_name, "input stream failed");
if (s.bad())
return hb_error (line_no, file_name, "bad input stream");
return hb_error (line_no, file_name, "unexpected input");
}
//
// if no integer read, set it to 0
//
template <class IteratorSize>
bool
getIoptional (std::istream& s, IteratorSize pi, int width = 14, bool is_required = false)
{
char I_buf [256];
if (is_required) {
s.get (I_buf, width+1);
} else {
if (s.peek() == '\n') {
// nothing to read: set default value = 0
*pi = 0;
return false;
}
// something to read...
s.get (I_buf, width+1);
}
if (!s) {
if (is_required) {
// s.state = fail or bad
return s.good();
} else {
// no integer read: set default value = 0
*pi = 0;
return s.good();
}
}
int tmp;
int n_read = sscanf (I_buf, "%d", &tmp);
warning_macro ("string("<<I_buf<<") -> int("<<tmp<<")");
*pi = tmp;
if (n_read != 1) {
#ifdef _RHEOLEF_HAVE_IOS_SETSTATE
if (is_required) {
// state = fail or bad
s.setstate(std::ios::failbit);
}
#endif // _RHEOLEF_HAVE_IOS_SETSTATE
if (!is_required) {
// no integer read: set default value = 0
*pi = 0;
}
}
return s.good();
}
//
// eat until eol
//
template <class Size>
bool
endofline (std::istream& s, Size nmax)
{
for (Size i = 0; i < nmax && s.peek() != '\n'; i++, s.get())
;
if (s.peek() != '\n') {
return false;
}
s.get();
return true;
}
//
// if no integer read, set bad/fail flag to istream
//
template <class IteratorSize>
bool
getI (std::istream& s, IteratorSize pi, int width = 14)
{
return getIoptional (s, pi, width, true);
}
//
// Converts a line with floats data in 'D' or 'd' format
// to 'E' or 'e' format by simply setting to 'E'
//
inline
void
convertDtoE (char* line)
{
for (int i = 0; line[i] != 0; i++)
if (line[i] == 'D' || line[i] == 'd')
line[i] = 'E';
}
inline
void
convertFDtoE (char* line)
{
for (int i = 0; line[i] != 0; i++)
if (line[i] == 'D' || line[i] == 'd' ||
line[i] == 'F' || line[i] == 'f' ||
line[i] == 'e' )
line[i] = 'E';
}
//
// Return the index of the first occurrence of C in S
// Return -1 if C does not occur in S
//
inline
int
getindex (const char* S, char C)
{
for (int i = 0; S [i] != 0; i++) {
if (S[i] == C)
return i;
}
return -1;
}
//
// convert S to uppercase
//
inline
void
upcase (char* S)
{
for (int i = 0; S[i] != 0; i++)
if ('a' <= S[i] && S[i] <= 'z' )
S[i] = S[i] + 'A' - 'a';
}
//
// read a positive integer in S after char C
// or -1 if error
//
inline
int
read_integer_after (const char* S, char C, char ALT_C = 0)
{
int pos = getindex (S, C);
if ((pos < 0 || S[pos+1] == 0) && ALT_C) getindex(S, ALT_C);
if (pos < 0 || S[pos+1] == 0) return -1;
int val = 0;
for (int i = pos+1; S[i] != 0 && isdigit(S[i]); i++)
val = 10*val + S[i] - '0';
return val;
}
//
// read a positive integer in S before char C
// or -1 if error
//
inline
int
read_integer_before (const char* S, char C, char ALT_C = 0)
{
int pos = getindex (S, C);
if (pos < 0 && ALT_C) getindex (S, ALT_C);
if (pos <= 0) return -1;
int val = 0;
int P = 1;
for (int i = pos-1; i >= 0 && isdigit(S[i]); i--) {
val = P*(S[i] - '0') + val;
P *= 10;
}
return val;
}
//
// parse an INTEGER format field to determine
// width and number of elements per line.
//
template <class Size>
bool
parse_ifmt (const char *fmt, Size line_no, const char *file_name, int *nperline, int *width)
{
char FMT [256];
strcpy (FMT, fmt);
upcase(FMT);
*nperline = read_integer_before (FMT, 'I', 'i');
*width = read_integer_after (FMT, 'I', 'i');
return (*nperline > 0 && *width > 0);
}
//
// Parse a REAL format field to determine
// width and number of elements per line.
// Also sets flag indicating 'E' 'F' 'P' or 'D'
// format.
//
template <class Size>
bool
parse_rfmt (const char *fmt, Size line_no, const char *file_name, int *nperline, int *width, bool *hasD)
{
// set flag: will need to put a E instead of a D in each input line !
*hasD = ((getindex (fmt, 'D') >= 0 || getindex (fmt, 'd') > 0));
char FMT [256];
strcpy (FMT, fmt);
convertFDtoE (FMT);
*nperline = read_integer_before (FMT, 'E');
*width = read_integer_after (FMT, 'E');
return (*nperline > 0 && *width > 0);
}
}// namespace rheolef
# endif // _SKIT_INHB_AUX_H
|