Blender V4.3
utility_io.cpp
Go to the documentation of this file.
1
4/*****************************************************************************
5 * Erwin Aertbelien, Div. PMA, Dep. of Mech. Eng., K.U.Leuven
6 *
7 * \version
8 * ORO_Geometry V0.2
9 *
10 * \par History
11 * - $log$
12 *
13 * \par Release
14 * $Name: $
15 * \todo
16 * make IO routines more robust against the differences between DOS/UNIX end-of-line style.
17 ****************************************************************************/
18
19
20#include "utility_io.h"
21#include "error.h"
22
23#include <stdlib.h>
24#include <ctype.h>
25#include <string.h>
26
27namespace KDL {
28
29//
30// _functions are private functions
31//
32
33 void _check_istream(std::istream& is)
34 {
35 if ((!is.good())&&(is.eof()) )
36 {
37 throw Error_BasicIO_File();
38 }
39 }
40// Eats until the end of the line
41static int _EatUntilEndOfLine( std::istream& is, int* countp=NULL) {
42 int ch;
43 int count;
44 count = 0;
45 do {
46 ch = is.get();
47 count++;
49 } while (ch!='\n');
50 if (countp!=NULL) *countp = count;
51 return ch;
52}
53
54// Eats until the end of the comment
55static int _EatUntilEndOfComment( std::istream& is, int* countp=NULL) {
56 int ch;
57 int count;
58 count = 0;
59 int prevch;
60 ch = 0;
61 do {
62 prevch = ch;
63 ch = is.get();
64 count++;
66 if ((prevch=='*')&&(ch=='/')) {
67 break;
68 }
69 } while (true);
70 if (countp!=NULL) *countp = count;
71 ch = is.get();
72 return ch;
73}
74
75// Eats space-like characters and comments
76// possibly returns the number of space-like characters eaten.
77static int _EatSpace( std::istream& is,int* countp=NULL) {
78 int ch;
79 int count;
80 count=-1;
81 do {
83
84 ch = is.get();
85 count++;
86 if (ch == '#') {
87 ch = _EatUntilEndOfLine(is,&count);
88 }
89 if (ch == '/') {
90 ch = is.get();
91 if (ch == '/') {
92 ch = _EatUntilEndOfLine(is,&count);
93 } else if (ch == '*') {
95 } else {
96 is.putback(ch);
97 ch = '/';
98 }
99 }
100 } while ((ch==' ')||(ch=='\n')||(ch=='\t'));
101 if (countp!=NULL) *countp = count;
102 return ch;
103}
104
105
106
107// Eats whites, returns, tabs and the delim character
108// Checks whether delim char. is encountered.
109void Eat( std::istream& is, int delim )
110{
111 int ch;
112 ch=_EatSpace(is);
113 if (ch != delim) {
115 }
116 ch=_EatSpace(is);
117 is.putback(ch);
118}
119
120// Eats whites, returns, tabs and the delim character
121// Checks whether delim char. is encountered.
122// EatEnd does not eat all space-like char's at the end.
123void EatEnd( std::istream& is, int delim )
124{
125 int ch;
126 ch=_EatSpace(is);
127 if (ch != delim) {
129 }
130}
131
132
133
134// For each space in descript, this routine eats whites,tabs, and newlines (at least one)
135// There should be no consecutive spaces in the description.
136// for each letter in descript, its reads the corresponding letter in the output
137// the routine is case insensitive.
138
139
140// Simple routine, enough for our purposes.
141// works with ASCII chars
142inline char Upper(char ch)
143{
144 /*if (('a'<=ch)&&(ch<='z'))
145 return (ch-'a'+'A');
146 else
147 return ch;
148 */
149 return toupper(ch);
150}
151
152void Eat(std::istream& is,const char* descript)
153{
154 // eats whites before word
155 char ch;
156 char chdescr;
157 ch=_EatSpace(is);
158 is.putback(ch);
159 const char* p;
160 p = descript;
161 while ((*p)!=0) {
162 chdescr = (char)Upper(*p);
163 if (chdescr==' ') {
164 int count=0;
165 ch=_EatSpace(is,&count);
166 is.putback(ch);
167 if (count==0) {
169 }
170 } else {
171 ch=(char)is.get();
172 if (chdescr!=Upper(ch)) {
174 }
175 }
176 p++;
177 }
178
179}
180
181
182
183void EatWord(std::istream& is,const char* delim,char* storage,int maxsize)
184{
185 int ch;
186 char* p;
187 int size;
188 // eat white before word
189 ch=_EatSpace(is);
190 p = storage;
191 size=0;
192 int count = 0;
193 while ((count==0)&&(strchr(delim,ch)==NULL)) {
194 *p = (char) toupper(ch);
195 ++p;
196 if (size==maxsize) {
197 throw Error_BasicIO_ToBig();
198 }
199 _check_istream(is);
200 ++size;
201 //ch = is.get();
202 ch =_EatSpace(is,&count);
203 }
204 *p=0;
205 is.putback(ch);
206}
207
208
209}
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
Definition btDbvt.cpp:52
#define NULL
int count
Definition chain.cpp:27
static int _EatUntilEndOfLine(std::istream &is, int *countp=NULL)
void EatEnd(std::istream &is, int delim)
void Eat(std::istream &is, int delim)
void EatWord(std::istream &is, const char *delim, char *storage, int maxsize)
static int _EatSpace(std::istream &is, int *countp=NULL)
char Upper(char ch)
static int _EatUntilEndOfComment(std::istream &is, int *countp=NULL)
void _check_istream(std::istream &is)